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
- Merge Intervals (Intermediate)
- Insert an Interval (Intermediate)
- Course Schedule Feasible (Intermediate)
- Weighted Job Scheduling (Intermediate)
- Minimum Number of Taps (Advanced)
- Minimum Number of Reflections (Advanced)
- Weighted Interval Scheduling Reconstruction (Advanced)
- Minimum Number of Buses (Intermediate)
- Find Right Interval (Intermediate)
- Common Free Time (Intermediate)
- Minimum Number of Perfect Squares (Intermediate)
- Calendar With Double Booking (Basic)
- Token Bucket Scheduler (Intermediate)
- Time Series Gap Detection (Advanced)
- Course Schedule Order (Intermediate)
- Minimum Difficulty of a Job Schedule (Advanced)
- Task Scheduler (Intermediate)
- Course Schedule III (Advanced)
- Two City Scheduling (Intermediate)
- Minimum Interval to Include Each Query (Advanced)
- Interval List Intersections (Intermediate)
- Meeting Rooms (Basic)
- Longest Well-Performing Interval (Advanced)
- My Calendar I (Intermediate)
- Assembly Line Scheduling (Intermediate)
- Remove Covered Intervals (Intermediate)
- Task Scheduler II (Intermediate)
- Minimum Flips to Make Binary String Alternating With Rotations (Advanced)
- Minimum Characters to Append for Palindrome (Intermediate)
- Minimum Suffix Increments to Make Array Non-Decreasing (Basic)
- Minimum Increments on Subarrays to Form Target (Intermediate)
- Minimum Removals for Strictly Increasing Array (Intermediate)
- Single-Element Increments to Sort Array (Basic)
- Minimum Cuts to Split Rectangle Into Squares (Advanced)
- Minimum Towers of Cubes (Intermediate)
- Maximum Reward Scheduling Tasks (Intermediate)
- Coin Redistribution Moves on Tree (Intermediate)
- Count Palindromic Times in Interval (Basic)
- Lights Out Minimum Presses (Advanced)
- Minimum Adjacent Swaps to Make Anagram Equal (Advanced)
- Minimum Changes to Make Palindrome (Basic)
- Minimum Trips to Carry All Items (Advanced)
- Operations to Equalize Array by Adding K (Intermediate)
- Minimum Increments for Strictly Increasing Array (Basic)
- Minimum Swaps to Fix Index Parity (Intermediate)
- Adjacent Swaps to Gather All Ones (Advanced)
- Palindrome Array Cost (Basic)
- Egyptian Fraction Greedy Term Count (Intermediate)
- Smallest Denominator Fraction in Interval (Advanced)
- Intervals Covering Point Queries (Intermediate)
- Minimum Darts to Finish (Advanced)
- Heartbeat Missed Alerts (Basic)
- Adjacent Swaps to Sort Letters (Intermediate)
- Rotations to Sort Ascending (Intermediate)
- Edges Needed to Connect Graph (Intermediate)
- Greedy Coin Count US (Basic)
- Total Union Length of Intervals (Intermediate)
- Deepest Interval Overlap (Intermediate)
- Idle Time Between Intervals (Intermediate)
- Merged Interval Count (Basic)
Related
- Sliding window problems
- Dynamic programming problems
- Graph problems
- Practice coding problems online
- All interview question topics
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.