Algorithms from zero
Greedy & intervals: interview drill
You understand the exchange argument. Interviews test whether you can spot the locally-optimal move under a timer, sort on the right key, and defend out loud why greedy stays optimal.
Solve each problem before you reveal a hint, hit the target time, and narrate the time and space complexity — and why the greedy choice is provably correct — as if an interviewer were listening. The hints exist for when you are genuinely stuck — they nudge you toward the pattern, never the full solution.
Five NeetCode-150 problems on the greedy and intervals patterns this unit teaches. Set a timer, solve each cold without looking at a hint, then say the time and space complexity out loud before you move on. Reveal a hint only when you are truly stuck — the hints nudge, they never hand you the answer.
0/5 solved
greedy
Follow-up (aloud)
State Kadane's invariant: what does the running value mean at each index, and why does carrying a negative prefix never help?
Follow-up (aloud)
This greedy is O(n) one pass. Prove that tracking only the farthest reachable index never misses a valid path.
intervals
Follow-up (aloud)
Because the input is pre-sorted, this is one linear pass. What is the overlap condition between two intervals, and where exactly do you test it?
Follow-up (aloud)
The sort dominates the cost. State the overall complexity and why, after sorting, a single linear sweep suffices.
Follow-up (aloud)
Give the exchange argument for why 'keep the earliest-finishing interval' is optimal. What breaks if you sort by start instead?
Mark each problem solved once you finished it cold, inside the target time, and could justify the greedy choice without hesitation. Come back in a few days and re-solve the ones you marked — spaced revisits are what turn a recognised pattern into a reflex.