Skip to main content

Complete Greedy Problems & Resources Guide

· 18 min read

Hey everyone! Greedy algorithms are one of the most elegant and intuitive problem-solving paradigms in computer science. I've spent years mastering greedy techniques for both interviews and competitive programming, and I want to share a complete guide that will transform how you approach optimization problems.

The key insight: Greedy algorithms are about making locally optimal choices that lead to globally optimal solutions. The challenge isn't implementation, it's recognizing when greedy works and proving correctness. Once you develop this intuition, you'll solve complex problems with surprisingly simple code.


Understanding Greedy Algorithms

What makes Greedy challenging? The algorithm itself is usually simple, but recognizing greedy opportunities and proving correctness requires deep problem understanding. Not all problems that seem greedy actually have greedy solutions, and distinguishing these cases is crucial.

For Tech Interviews: You need to master core patterns: activity selection, interval scheduling, fractional knapsack, huffman coding variants, and greedy with sorting. About 70-90 well-understood problems is ideal. The key is explaining WHY your greedy choice works.

For Competitive Programming: You need to recognize non-obvious greedy problems, prove correctness using exchange arguments, and combine greedy with other techniques like DP, graphs, and data structures. This requires 120-150+ problems and strong mathematical intuition.


Best Learning Resources

Video Resources for Interview Prep

NeetCode - Greedy - Excellent for learning interview greedy patterns. Clear explanations of when and why greedy works. Best resource for building intuition.

take U forward (Striver) - Greedy Algorithms - Comprehensive coverage with detailed correctness proofs. 25+ hours of content covering all major patterns.

Back To Back SWE - Greedy Problems - Excellent for understanding the thought process behind greedy solutions. Great for learning to explain your reasoning.

Abdul Bari - Greedy Method - Best for understanding theoretical foundations. Covers activity selection, fractional knapsack, and correctness proofs clearly.

MIT OCW - Greedy Algorithms - Academic perspective with rigorous proofs. Excellent for understanding when greedy works vs when it fails.

Video Resources for Competitive Programming

Errichto - Greedy Techniques - Advanced greedy for CP. Shows non-obvious greedy problems and exchange argument proofs. Contest problem walkthroughs.

SecondThread - Greedy + Data Structures - Combining greedy with priority queues, sets, and other structures. Advanced optimization techniques.

William Fiset - Greedy Algorithms - Clear explanations of classic greedy algorithms with code implementations.

Colin Galen - Contest Greedy Problems - Real contest problems showing how to recognize greedy opportunities quickly.

Written Resources

For Interviews:

For Competitive Programming:

Books Worth Reading

Introduction to Algorithms (CLRS) - Chapter on greedy algorithms with rigorous proofs of correctness. Essential reading.

Algorithm Design Manual by Skiena - Great greedy problems with war stories showing real-world applications.

Algorithm Design by Kleinberg & Tardos - Excellent coverage of greedy algorithms with detailed correctness proofs.

Competitive Programming 4 - Comprehensive greedy techniques for contests with problem classifications.

The Algorithm Design Manual - Practical approach to greedy with implementation advice.


Interview Problems (90 Total)

Phase 1: Basic Greedy - Sorting First (15 problems)

Foundation problems where sorting is the key insight.

  1. Assign Cookies
  2. Maximize Sum Of Array After K Negations
  3. Largest Perimeter Triangle
  4. Maximum Units on a Truck
  5. Minimum Subsequence in Non-Increasing Order
  6. Array Partition
  7. Boats to Save People
  8. Minimum Cost to Move Chips to The Same Position
  9. Broken Calculator
  10. Minimum Additions to Make Valid String
  11. Can Place Flowers
  12. Lemonade Change
  13. Walking Robot Simulation
  14. Minimum Number of Arrows to Burst Balloons
  15. Two City Scheduling

Phase 2: Interval Problems (15 problems)

Classic greedy pattern. Master activity selection and its variants.

  1. Meeting Rooms
  2. Meeting Rooms II
  3. Merge Intervals
  4. Insert Interval
  5. Non-overlapping Intervals
  6. Minimum Number of Arrows to Burst Balloons
  7. Interval List Intersections
  8. Employee Free Time
  9. Remove Covered Intervals
  10. Maximum Number of Events That Can Be Attended
  11. Maximum Profit in Job Scheduling
  12. Divide Intervals Into Minimum Number of Groups
  13. Maximum Number of Events That Can Be Attended II
  14. Minimum Interval to Include Each Query
  15. Car Pooling

Phase 3: Greedy with Two Pointers (10 problems)

Combining greedy strategy with two-pointer technique.

  1. Container With Most Water
  2. Bag of Tokens
  3. Boats to Save People
  4. Valid Triangle Number
  5. 3Sum Smaller
  6. Minimize Maximum Pair Sum in Array
  7. Partition Array Into Three Parts With Equal Sum
  8. Minimum Number of Moves to Make Palindrome
  9. Longest Happy String
  10. Construct K Palindrome Strings

Phase 4: Greedy String Problems (10 problems)

String manipulation with greedy strategy.

  1. Remove K Digits
  2. Remove Duplicate Letters
  3. Smallest Subsequence of Distinct Characters
  4. Partition Labels
  5. Split a String in Balanced Strings
  6. Minimum Deletions to Make Character Frequencies Unique
  7. Longest Happy String
  8. Construct String from Binary Tree
  9. Minimum Number of Swaps to Make the String Balanced
  10. Maximum Number of Removable Characters

Phase 5: Greedy with Priority Queue/Heap (15 problems)

Essential pattern combining greedy with heap data structure.

  1. Last Stone Weight
  2. Meeting Rooms II
  3. Task Scheduler
  4. Reorganize String
  5. Minimum Cost to Hire K Workers
  6. IPO
  7. Find K Pairs with Smallest Sums
  8. Kth Largest Element in an Array
  9. Top K Frequent Elements
  10. Maximum Performance of a Team
  11. Minimum Cost to Connect Sticks
  12. Reduce Array Size to The Half
  13. Maximum Number of Events That Can Be Attended
  14. Furthest Building You Can Reach
  15. Seat Reservation Manager

Phase 6: Jump Game & Reachability (8 problems)

Classic greedy pattern about reaching goals optimally.

  1. Jump Game
  2. Jump Game II
  3. Jump Game III
  4. Jump Game IV
  5. Jump Game V
  6. Jump Game VI
  7. Jump Game VII
  8. Minimum Number of Taps to Open to Water a Garden

Phase 7: Stock Problems & State Transitions (7 problems)

Greedy approach to optimization with state changes.

  1. Best Time to Buy and Sell Stock
  2. Best Time to Buy and Sell Stock II
  3. Best Time to Buy and Sell Stock with Transaction Fee
  4. Best Time to Buy and Sell Stock with Cooldown
  5. Wiggle Subsequence
  6. Maximum Subarray
  7. Maximum Sum Circular Subarray

Phase 8: Advanced Greedy (10 problems)

Complex problems requiring creative greedy insights.

  1. Gas Station
  2. Candy
  3. Queue Reconstruction by Height
  4. Minimum Number of Refueling Stops
  5. Patching Array
  6. Create Maximum Number
  7. Remove Boxes
  8. Smallest Range Covering Elements from K Lists
  9. Advantage Shuffle
  10. Hand of Straights

Competitive Programming Problems

AtCoder Greedy Problems (25 problems)

  1. ABC 087 C - Candies
  2. ABC 088 C - Takahashi's Information
  3. ABC 093 C - Same Integers
  4. ABC 103 D - Islands War
  5. ABC 121 D - XOR World
  6. ABC 131 D - Megalomania
  7. ABC 142 D - Disjoint Set of Common Divisors
  8. ABC 149 D - Prediction and Restriction
  9. ABC 161 D - Lunlun Number
  10. ABC 169 D - Div Game
  11. ABC 184 D - increment of coins
  12. ABC 197 D - Opposite
  13. ABC 214 D - Sum of Maximum Weights
  14. ABC 229 D - Longest X
  15. ABC 246 D - 2-variable Function
  16. ABC 252 D - Distinct Trio
  17. ABC 267 D - Index × A(Not Continuous ver.)
  18. ABC 276 D - Divide by 2 or 3
  19. ABC 289 D - Step Up Robot
  20. ARC 067 D - Walk and Teleport
  21. ARC 091 D - Remainder Reminder
  22. ABC 303 D - Shift vs. CapsLock
  23. ABC 311 D - Grid Ice Floor
  24. ABC 317 D - President
  25. ABC 323 D - Merge Slimes

CSES Greedy Problems (10 problems)

  1. Ferris Wheel
  2. Concert Tickets
  3. Restaurant Customers
  4. Movie Festival
  5. Movie Festival II
  6. Tasks and Deadlines
  7. Reading Books
  8. Sum of Three Values
  9. Stick Lengths
  10. Missing Coin Sum

Codeforces Greedy Problems by Rating

Rating 800-1000 (Beginner):

  1. Round 479 Div3 - A - Wrong Subtraction
  2. Round 486 Div3 - A - Diverse Team
  3. Round 535 Div3 - A - Two Distinct Points
  4. Round 661 Div3 - A - Remove Smallest
  5. Round 693 Div3 - A - Zodiac Sign

Rating 1000-1200 (Easy):

  1. Round 344 Div2 - B - Print Check
  2. Round 367 Div2 - B - Interesting drink
  3. Round 380 Div2 - B - Spotlights
  4. Round 479 Div3 - B - Trace
  5. Round 535 Div3 - B - Diverse Strings

Rating 1200-1400 (Medium):

  1. Round 256 Div2 - B - Suffix Structures
  2. Round 268 Div2 - B - Books
  3. Round 290 Div2 - B - Fox And Two Dots
  4. Round 321 Div2 - B - Kefa and Company
  5. Round 348 Div2 - B - Little Robber Girl's Zoo

Rating 1400-1600 (Advanced):

  1. Round 243 Div2 - C - Sereja and Swaps
  2. Round 256 Div2 - C - Painting Fence
  3. Round 283 Div2 - C - Removing Columns
  4. Round 290 Div2 - C - Fox And Names
  5. Round 325 Div2 - C - Gennady the Dentist

Rating 1600-1800 (Expert):

  1. Round 211 Div2 - D - Sereja and Cinema
  2. Round 233 Div2 - D - Sereja and Squares
  3. Round 268 Div2 - C - The Sports Festival
  4. Round 285 Div2 - C - Misha and Forest
  5. Round 321 Div2 - C - Kefa and Park

Rating 1800-2000 (Candidate Master):

  1. Round 196 Div2 - D - Hexagons
  2. Round 243 Div2 - D - Sereja and Squares
  3. Round 256 Div2 - D - Multiplication Table
  4. Round 283 Div2 - D - Tennis Game
  5. Round 290 Div2 - D - Fox And Jumping

Advanced CP Topics

Greedy + DP (Optimization):

  1. CF - Divisibility by Eight
  2. CF - Exams
  3. SPOJ - PIGBANK
  4. CF - Cut Ribbon
  5. AtCoder - Knapsack 1

Exchange Argument Problems:

  1. CF - Sereja and Dima
  2. CF - Magic Numbers
  3. CSES - Tasks and Deadlines
  4. CF - Towers
  5. AtCoder - Many Moves

Greedy with Observations:

  1. CF - Little Elephant and Bits
  2. CF - Divisibility
  3. AtCoder - Make Them Equal
  4. CF - Array Cancellation
  5. CSES - Missing Coin Sum

Greedy with Priority Queue:

  1. CF - Office Keys
  2. CF - Sequence
  3. SPOJ - ARRANGE
  4. CF - Maximum Subsequence
  5. AtCoder - Intervals

Greedy on Graphs:

  1. CF - Dijkstra?
  2. CSES - Shortest Routes I
  3. CF - Minimum spanning tree
  4. AtCoder - Lazy Segment Tree
  5. SPOJ - MST

Learning Timeline

For Interview Preparation (5-6 weeks)

Week 1: Greedy Foundations Solve all 15 problems from Phase 1. Understand the core principle: sort first, then make greedy choices. Learn to recognize when sorting helps. Master proving simple greedy solutions correct.

Week 2: Interval Problems Complete all 15 problems from Phase 2. This is THE most important greedy pattern for interviews. Master activity selection and all its variants. Learn to prove correctness using exchange arguments.

Week 3: Greedy with Data Structures Solve Phase 3 (10 problems) and Phase 4 (10 problems). Learn to combine greedy with two pointers and string manipulation. Understand when greedy works for string problems.

Week 4: Priority Queue Mastery Complete Phase 5 (15 problems). Master combining greedy with heaps. This pattern appears constantly in advanced problems. Understand when a priority queue enables greedy solutions.

Week 5: Jump Games & Stocks Solve Phase 6 (8 problems) and Phase 7 (7 problems). Master reachability problems and state transitions. These are classic greedy patterns that appear frequently.

Week 6: Advanced Greedy & Review Complete Phase 8 (10 problems). Practice the hardest greedy problems. Do mock interviews. Focus on explaining WHY your greedy choice works. Review problems where you struggled to see the greedy insight.

For Competitive Programming (4-5 months)

Month 1: Strong Foundation Complete all CSES greedy problems. Solve AtCoder problems 1-15. Practice Codeforces 800-1200 rated problems. Master basic greedy patterns and sorting. Learn to write clean proofs. Target 50-60 problems.

Month 2: Exchange Arguments Study exchange argument technique deeply. Solve 1200-1500 rated problems. Learn to recognize when greedy works vs when DP is needed. Practice proving correctness rigorously. Target 40-50 problems.

Month 3: Advanced Patterns Master greedy with priority queues and sets. Learn interval scheduling variants. Study greedy on graphs (MST, shortest paths). Solve 1500-1700 rated problems. Target 35-45 problems.

Month 4: Observation-Based Greedy Learn to find mathematical observations that enable greedy. Practice non-obvious greedy problems. Combine greedy with other techniques. Solve 1600-1800 rated problems. Target 30-40 problems.

Month 5: Mastery & Speed Participate in virtual contests. Focus on recognizing greedy opportunities instantly. Practice writing correctness proofs quickly. Solve 1800+ rated problems. Target 25-30 problems.


Final Thoughts

Greedy algorithms are beautiful because they're simple yet powerful. The challenge isn't implementation—it's recognizing when greedy works and proving correctness.

For interviews, focus on understanding WHY greedy works for each problem. Master interval scheduling, priority queue patterns, and sorting-based greedy. Solve 70-90 problems and you'll be well-prepared. The key is explaining your greedy choice clearly.

For competitive programming, you need instant pattern recognition and the ability to construct exchange argument proofs quickly. Practice distinguishing greedy from DP problems. Master combining greedy with advanced data structures.

Remember: Greedy algorithms make locally optimal choices. The art is in proving these local choices lead to global optimality. Master this, and you've mastered one of the most elegant problem-solving paradigms in computer science.