Maximum Task Reward Within a Time Budget
Updated
Problem statement
You are given parallel arrays timeCosts and rewards. Task i requires timeCosts[i] units of time and earns rewards[i] reward.
You may select each task at most once, and the total time of selected tasks must not exceed maxTime. Return the maximum total reward you can earn.
Function
maximumTaskReward(timeCosts: int[], rewards: int[], maxTime: int) → longExamples
Example 1
timeCosts = [2,3,4]rewards = [4,5,7]maxTime = 5return = 9Select the tasks with time costs 2 and 3 for total reward 4 + 5 = 9.
Example 2
timeCosts = [5,4,6]rewards = [10,7,12]maxTime = 4return = 7Only the task with time cost 4 fits.
Example 3
timeCosts = [1,1,1]rewards = [2,3,4]maxTime = 2return = 7Select the two highest-reward tasks. Each task may be used only once.
Constraints
1 <= timeCosts.length = rewards.length <= 10001 <= timeCosts[i] <= 100000 <= rewards[i] <= 10000000000 <= maxTime <= 10000- The answer fits in a signed 64-bit integer.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Assign Escalations to TeamsAmazon · ONSITE INTERVIEW
- 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
- Word BreakMoveworks · ONSITE INTERVIEWMoveworks interview questions
- Maximum Value from Circular HousesDigitalOcean · ONSITE INTERVIEWDigitalOcean interview questions