Maximum Profit from Non-Overlapping Jobs
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on this Google OA, reported September 2026, is treating it like plain interval scheduling and greedily grabbing the biggest profit. It's weighted job scheduling, a dynamic programming problem with a binary search on top. Jobs have a start, an end, and a profit, and a job starting exactly when another ends is allowed. With up to 100000 jobs, an O(n^2) DP won't survive. If you blank mid-assessment, StealthCoder is the invisible safety net that reads the problem on screen and hands you the approach. Here's the script so you don't need it.
The problem
Job i starts at startTime[i], ends at endTime[i], and earns profit[i]. Choose a subset of non-overlapping jobs with maximum total profit. A job that starts exactly when another selected job ends does not overlap it. Function maximumJobProfit(startTime: int[], endTime: int[], profit: int[]) → long Examples Example 1 startTime = [1,2,3,3] endTime = [3,4,5,6] profit = [50,10,40,70] return = 120 Select jobs [1,3] and [3,6]. Example 2 startTime = [1,2,3,4,6] endTime = [3,5,10,6,9] profit = [20,20,100,70,60] return = 150 The jobs spanning [1,3], [4,6], and [6,9] earn 150. Example 3 startTime = [1] endTime = [2] profit = [7] return = 7 The only job is selected. Constraints 1 <= startTime.length == endTime.length == profit.length <= 100000. 1 <= startTime[i] < endTime[i] <= 10^9. 1 <= profit[i] <= 10^9.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Sort jobs by end time. Let dp[i] be the best profit using the first i jobs in that order. For each job, you either skip it, giving dp[i-1], or take it, giving its profit plus dp[j], where j is the count of jobs whose end time is less than or equal to this job's start time. Find j with binary search on the sorted end times, using upper bound so a job ending exactly at the start counts as compatible. That's the classic pitfall: using strict less-than drops valid answers like Example 1. Another trap is overflow. Profits reach 10^9 across 100000 jobs, so use 64-bit sums. Total cost is O(n log n). If the recurrence slips away during the live OA, StealthCoder can surface it, but the sort-then-binary-search shape is the whole trick.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Maximum Profit from Non-Overlapping Jobs cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as maximum profit in job scheduling. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Maximum Profit from Non-Overlapping Jobs FAQ
What's the trick to Maximum Profit from Non-Overlapping Jobs?+
Sort by end time, then run a DP where each job is either skipped or taken. If taken, add the best dp value over all jobs ending at or before its start. Binary search finds that previous job fast. Greedy by profit or by earliest end fails because profits differ.
Why does greedy fail here?+
Picking the highest profit job can block several smaller jobs that sum to more. In Example 2, the 100 profit job spans [3,10] and blocks everything else, yet the three-job combo earns 150. You need to compare take versus skip at every job, which is what the DP does.
How do I handle jobs that touch at the boundary?+
The problem says a job starting exactly when another ends doesn't overlap. So when searching for the last compatible job, accept end time <= start time. Use an upper-bound style binary search. Using strict less-than is the most common off-by-one bug and it breaks Example 1.
Will an O(n^2) solution pass?+
Not with n up to 100000. Scanning back through all earlier jobs for each one is quadratic and will time out. Sorting plus binary search gives O(n log n), which is what Google expects for this constraint size.
How do I prepare for this in 48 hours?+
Write the solution once from scratch: sort by end, build an end-time array, binary search per job, and keep a dp array of longs. Test on the three examples, then a single job case. Know why the return type is long. That's enough for this pattern.