Greedy Problems for Coding Interviews

A greedy algorithm makes the best local choice at each step and never revisits it. It is correct only when a local optimum leads to a global one, so the interview is about justifying the choice, usually with an exchange argument.

Typical problems are interval scheduling, jump game, gas station and assigning resources. Practise sorting by the right key, then compare with a dynamic programming solution to see why the greedy one is valid or fails.

Coding problems

Related

Frequently asked questions

How do I get good at greedy problems?

Solve a few problems of each difficulty, name the pattern after you solve each one, and revisit the ones you needed hints for a week later. The list on this page is ordered so you can start with the basic ones.

Can I run greedy problems online here?

Yes. Every problem opens in an editor that runs your code against test cases in Java, Python, C++, Go, JavaScript and six more languages, with no setup.