Complete Greedy Problems & Resources Guide
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:
- LeetCode Greedy Explore Card
- Tech Interview Handbook - Greedy
- GeeksforGeeks Greedy Algorithms
- InterviewBit - Greedy
For Competitive Programming:
- CP-Algorithms - Greedy
- Codeforces Greedy Problems Catalog
- USACO Guide - Greedy with Sorting
- TopCoder Greedy Tutorial
- Brilliant.org - Greedy Algorithms
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.
- Assign Cookies
- Maximize Sum Of Array After K Negations
- Largest Perimeter Triangle
- Maximum Units on a Truck
- Minimum Subsequence in Non-Increasing Order
- Array Partition
- Boats to Save People
- Minimum Cost to Move Chips to The Same Position
- Broken Calculator
- Minimum Additions to Make Valid String
- Can Place Flowers
- Lemonade Change
- Walking Robot Simulation
- Minimum Number of Arrows to Burst Balloons
- Two City Scheduling
Phase 2: Interval Problems (15 problems)
Classic greedy pattern. Master activity selection and its variants.
- Meeting Rooms
- Meeting Rooms II
- Merge Intervals
- Insert Interval
- Non-overlapping Intervals
- Minimum Number of Arrows to Burst Balloons
- Interval List Intersections
- Employee Free Time
- Remove Covered Intervals
- Maximum Number of Events That Can Be Attended
- Maximum Profit in Job Scheduling
- Divide Intervals Into Minimum Number of Groups
- Maximum Number of Events That Can Be Attended II
- Minimum Interval to Include Each Query
- Car Pooling
Phase 3: Greedy with Two Pointers (10 problems)
Combining greedy strategy with two-pointer technique.
- Container With Most Water
- Bag of Tokens
- Boats to Save People
- Valid Triangle Number
- 3Sum Smaller
- Minimize Maximum Pair Sum in Array
- Partition Array Into Three Parts With Equal Sum
- Minimum Number of Moves to Make Palindrome
- Longest Happy String
- Construct K Palindrome Strings
Phase 4: Greedy String Problems (10 problems)
String manipulation with greedy strategy.
- Remove K Digits
- Remove Duplicate Letters
- Smallest Subsequence of Distinct Characters
- Partition Labels
- Split a String in Balanced Strings
- Minimum Deletions to Make Character Frequencies Unique
- Longest Happy String
- Construct String from Binary Tree
- Minimum Number of Swaps to Make the String Balanced
- Maximum Number of Removable Characters
Phase 5: Greedy with Priority Queue/Heap (15 problems)
Essential pattern combining greedy with heap data structure.
- Last Stone Weight
- Meeting Rooms II
- Task Scheduler
- Reorganize String
- Minimum Cost to Hire K Workers
- IPO
- Find K Pairs with Smallest Sums
- Kth Largest Element in an Array
- Top K Frequent Elements
- Maximum Performance of a Team
- Minimum Cost to Connect Sticks
- Reduce Array Size to The Half
- Maximum Number of Events That Can Be Attended
- Furthest Building You Can Reach
- Seat Reservation Manager
Phase 6: Jump Game & Reachability (8 problems)
Classic greedy pattern about reaching goals optimally.
- Jump Game
- Jump Game II
- Jump Game III
- Jump Game IV
- Jump Game V
- Jump Game VI
- Jump Game VII
- 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.
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock II
- Best Time to Buy and Sell Stock with Transaction Fee
- Best Time to Buy and Sell Stock with Cooldown
- Wiggle Subsequence
- Maximum Subarray
- Maximum Sum Circular Subarray
Phase 8: Advanced Greedy (10 problems)
Complex problems requiring creative greedy insights.
- Gas Station
- Candy
- Queue Reconstruction by Height
- Minimum Number of Refueling Stops
- Patching Array
- Create Maximum Number
- Remove Boxes
- Smallest Range Covering Elements from K Lists
- Advantage Shuffle
- Hand of Straights
Competitive Programming Problems
AtCoder Greedy Problems (25 problems)
- ABC 087 C - Candies
- ABC 088 C - Takahashi's Information
- ABC 093 C - Same Integers
- ABC 103 D - Islands War
- ABC 121 D - XOR World
- ABC 131 D - Megalomania
- ABC 142 D - Disjoint Set of Common Divisors
- ABC 149 D - Prediction and Restriction
- ABC 161 D - Lunlun Number
- ABC 169 D - Div Game
- ABC 184 D - increment of coins
- ABC 197 D - Opposite
- ABC 214 D - Sum of Maximum Weights
- ABC 229 D - Longest X
- ABC 246 D - 2-variable Function
- ABC 252 D - Distinct Trio
- ABC 267 D - Index × A(Not Continuous ver.)
- ABC 276 D - Divide by 2 or 3
- ABC 289 D - Step Up Robot
- ARC 067 D - Walk and Teleport
- ARC 091 D - Remainder Reminder
- ABC 303 D - Shift vs. CapsLock
- ABC 311 D - Grid Ice Floor
- ABC 317 D - President
- ABC 323 D - Merge Slimes
CSES Greedy Problems (10 problems)
- Ferris Wheel
- Concert Tickets
- Restaurant Customers
- Movie Festival
- Movie Festival II
- Tasks and Deadlines
- Reading Books
- Sum of Three Values
- Stick Lengths
- Missing Coin Sum
Codeforces Greedy Problems by Rating
Rating 800-1000 (Beginner):
- Round 479 Div3 - A - Wrong Subtraction
- Round 486 Div3 - A - Diverse Team
- Round 535 Div3 - A - Two Distinct Points
- Round 661 Div3 - A - Remove Smallest
- Round 693 Div3 - A - Zodiac Sign
Rating 1000-1200 (Easy):
- Round 344 Div2 - B - Print Check
- Round 367 Div2 - B - Interesting drink
- Round 380 Div2 - B - Spotlights
- Round 479 Div3 - B - Trace
- Round 535 Div3 - B - Diverse Strings
Rating 1200-1400 (Medium):
- Round 256 Div2 - B - Suffix Structures
- Round 268 Div2 - B - Books
- Round 290 Div2 - B - Fox And Two Dots
- Round 321 Div2 - B - Kefa and Company
- Round 348 Div2 - B - Little Robber Girl's Zoo
Rating 1400-1600 (Advanced):
- Round 243 Div2 - C - Sereja and Swaps
- Round 256 Div2 - C - Painting Fence
- Round 283 Div2 - C - Removing Columns
- Round 290 Div2 - C - Fox And Names
- Round 325 Div2 - C - Gennady the Dentist
Rating 1600-1800 (Expert):
- Round 211 Div2 - D - Sereja and Cinema
- Round 233 Div2 - D - Sereja and Squares
- Round 268 Div2 - C - The Sports Festival
- Round 285 Div2 - C - Misha and Forest
- Round 321 Div2 - C - Kefa and Park
Rating 1800-2000 (Candidate Master):
- Round 196 Div2 - D - Hexagons
- Round 243 Div2 - D - Sereja and Squares
- Round 256 Div2 - D - Multiplication Table
- Round 283 Div2 - D - Tennis Game
- Round 290 Div2 - D - Fox And Jumping
Advanced CP Topics
Greedy + DP (Optimization):
Exchange Argument Problems:
Greedy with Observations:
- CF - Little Elephant and Bits
- CF - Divisibility
- AtCoder - Make Them Equal
- CF - Array Cancellation
- CSES - Missing Coin Sum
Greedy with Priority Queue:
Greedy on Graphs:
- CF - Dijkstra?
- CSES - Shortest Routes I
- CF - Minimum spanning tree
- AtCoder - Lazy Segment Tree
- 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.