Budget-Constrained Project Selection
Updated
Problem statement
You are given two arrays costs and values of equal length. Project i costs costs[i] units of budget and contributes values[i] units of value.
Select any subset of projects so that:
- Each project is selected at most once.
- The total selected cost does not exceed
budget.
Return the maximum total value of a valid selection. Selecting no projects is allowed and has value 0.
Function
maximizeProjectValue(costs: int[], values: int[], budget: int) → longExamples
Example 1
costs = [2,3,4]values = [4,5,10]budget = 6return = 14Select the projects with costs 2 and 4. Their total cost is 6 and their total value is 14.
Example 2
costs = [5,6]values = [10,12]budget = 4return = 0No project fits within the budget, so the empty selection is optimal.
Example 3
costs = [1,2,3]values = [6,10,12]budget = 5return = 22Select the projects with costs 2 and 3 for total value 22.
Constraints
1 <= costs.length = values.length <= 2001 <= costs[i] <= 10^50 <= values[i] <= 10^90 <= budget <= 10^5- The maximum answer fits in a signed 64-bit integer.
More Salesforce Onsite Interview questions
- Count Increasing TripletsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Reverse a Sublist of a Linked ListONSITE INTERVIEW · Seen Nov 2026
- Rotting OrangesONSITE INTERVIEW · Seen Nov 2026
- 3Sum SmallerONSITE INTERVIEW · Seen Nov 2026
- Count Zero Request ServersONSITE INTERVIEW · Seen Nov 2026
- Group Identical Tree LevelsONSITE INTERVIEW · Seen Oct 2026
- Meeting Rooms IIONSITE INTERVIEW · Seen Oct 2026
- Construct a Tree from Level-Order and Inorder TraversalsONSITE INTERVIEW · Seen Sep 2026
- Maximize Monsters DefeatedONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Maximum Sum with K-Element SkippingPhonePe · ONSITE INTERVIEWPhonePe interview questions
- Assign Escalations to TeamsAmazon · ONSITE INTERVIEW
- Distinct Subset SumsGoogle · ONSITE INTERVIEWGoogle interview questions
- Count Subsets With a Target SumSafe Security · ONSITE INTERVIEW
- Maximum Subarray Sum with One DeletionOracle · ONSITE INTERVIEWOracle interview questions
- Best Time to Buy and Sell Stock IIKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Coin ChangeMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Maximum SubarrayUpstart · ONSITE INTERVIEWUpstart interview questions
- Smallest Sufficient TeamExpedia · ONSITE INTERVIEWExpedia interview questions
- Maximum Product SubarrayHartford Financial Services · ONSITE INTERVIEWHartford Financial Services interview questions