Maximum Payout with Context Switches
Updated
Problem statement
You are given two arrays, payoutA and payoutB, of equal length. Index i represents one task slot in a fixed sequence. In that slot, you may skip the slot, complete Startup A's task for payoutA[i], or complete Startup B's task for payoutB[i].
You may complete at most maxTasks tasks. Every completed task costs one day. If a completed task belongs to a different startup than the previous completed task, it also costs one idle context-switch day. Skipped slots consume no days and do not change the startup of the previous completed task.
The total number of task days plus context-switch days must not exceed days. Return the maximum total payout. Choosing no tasks is allowed and yields 0.
Function
maximumPayout(payoutA: int[], payoutB: int[], maxTasks: int, days: int) → longExamples
Example 1
payoutA = [5,1,10]payoutB = [1,8,2]maxTasks = 2days = 2return = 15Complete Startup A's tasks in slots 0 and 2. They cost two task days, require no context switch, and pay 5 + 10 = 15.
Example 2
payoutA = [5,1,10]payoutB = [1,8,2]maxTasks = 2days = 3return = 18Complete Startup B's task in slot 1 and Startup A's task in slot 2. The two tasks and one switch consume three days, and the payout is 8 + 10 = 18.
Example 3
payoutA = [7,4]payoutB = [6,9]maxTasks = 0days = 4return = 0No task may be completed when maxTasks is 0, so the maximum payout is 0.
Constraints
1 <= payoutA.length = payoutB.length <= 1000 <= payoutA[i], payoutB[i] <= 10^90 <= maxTasks <= payoutA.length0 <= days <= 2 * payoutA.length
More PhonePe interview questions
- Constrained Jump SequencesOA · Seen Aug 2026
- Substrings Without a Target SubsequenceOA · Seen Aug 2026
- Luna and the Colorful SocksOA · Seen Jul 2026
- Evaluate DivisionONSITE INTERVIEW · Seen Oct 2026
- K-th Smallest Value in a Sorted MatrixONSITE INTERVIEW · Seen Oct 2026
- Identify Two Failing Tests From an Oracle TranscriptONSITE INTERVIEW · Seen Sep 2026
- Count Bowl SubarraysONSITE INTERVIEW · Seen Jul 2026
- Reconstruct ItineraryONSITE INTERVIEW · Seen Jul 2026
Similar questions at other companies
- Split Array to Minimize the Largest SumInfosys · OAInfosys interview questions
- Largest Consistent Visiting GroupAuxoAI · OA
- Delete K Subsets for Maximum ScoreRubrik · OARubrik interview questions
- Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
- Maximum Index-Weighted Sum with Disjoint SwapsVisa · OAVisa interview questions
- Maximum Sum of HeightsVirtu Financial · OAVirtu Financial interview questions
- Pressure-Isolation Shutdown OrderIntuit · OAIntuit interview questions
- Get Minimum IncrementIBM · OAIBM interview questions
- Jump Game with Prime-3 StepsUber · OAUber interview questions
- Maximize Array Beauty After DeletionsPoint72 · OAPoint72 interview questions