The core idea clicked pretty fast: sort by end time, then build up a DP where each entry is either skip the current job or take it plus whatever the best non-conflicting prefix gives you.
Sort the jobs by end time, then use dynamic programming where dp[i] represents the maximum profit using the first i jobs. For each job i, find the latest non-overlapping job j (using binary search on end times) and compute dp[i] = max(dp[i-1], profit[i] + dp[j]).
Pro tip: Clarify the non-overlap condition: jobs sharing an endpoint are allowed, so when finding the latest non-overlapping job, use end_time <= start_time (not <). This subtlety often trips up candidates.
Confirm the non-overlap rule (shared endpoints allowed) and sort jobs by end time. This ordering ensures that when considering a job, all compatible jobs appear earlier.
Define dp[i] as the maximum profit achievable using the first i jobs (sorted by end time). The answer will be dp[n].
For each job i, use binary search on the sorted end times to find the largest index j < i such that end_time[j] <= start_time[i]. This gives the latest job that doesn't overlap with job i.
Compute dp[i] = max(dp[i-1], profit[i] + dp[j]). Iterate i from 1 to n, filling the DP table.
Return dp[n]. Explain that sorting takes O(n log n) and the DP with binary search takes O(n log n) time, with O(n) space.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.