ORIGINAL CODING QUESTION
Course budget skill value
Each optional course has a cost and a skill value. Pick courses, each at most once, whose total cost stays within the training budget. Return the greatest total skill value. Courses that cost 0 always fit.
Original exercise · medium. Editorial role relevance does not imply a company has asked this question.
Input and output
n, then n cost/value pairs, then the budget.
Constraints
1 ≤ n ≤ 12; 0 ≤ cost ≤ 100; 0 ≤ value ≤ 100; 0 ≤ budget ≤ 1000.
Example 1
Input
4 1 1 3 4 4 5 5 7 7
Output
9
The courses costing 3 and 4 fit the budget of 7 and give 9.
Example 2
Input
2 5 10 6 12 4
Output
0
Every course costs more than the budget.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
Each course is either taken once or not at all.
Hint 2
Let best[b] be the greatest value achievable with spend at most b.
Hint 3
Process courses one by one and update budgets from high to low so a course is not reused.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →