← Whiteboard questions

Pattern

Greedy

Use a greedy method when the best local choice at each step never hurts the final answer. The hard part is the proof: show that swapping in another choice cannot do better. When it holds, the cost is usually a sort plus one pass.

Greedy interview questions and solutions