Greedy
A greedy algorithm makes the locally best choice at each step and never reconsiders — fast, but only correct when local optimality guarantees a global optimum. The hard part is proving (or trusting) that the greedy choice is safe.
24 LeetCode problems solved with the Greedy pattern. Practice them with spaced repetition so the pattern sticks.
- Assign CookiesEASY · O(n log n + m log m)
- Best Time to Buy and Sell Stock IIMEDIUM · O(n)
- Boats to Save PeopleMEDIUM · O(n log n)
- Can Place FlowersEASY · O(n)
- CandyHARD · O(n)
- Dota2 SenateMEDIUM · O(n)
- Gas StationMEDIUM · O(n)
- Hand of StraightsMEDIUM · O(n log n)
- Increasing Triplet SubsequenceMEDIUM · O(n)
- Jump GameMEDIUM · O(n)
- Jump Game IIMEDIUM · O(n)
- Lemonade ChangeEASY · O(n)
- Longest Happy StringMEDIUM · O(a + b + c)
- Majority ElementEASY · O(n)
- Maximize Sum Of Array After K NegationsEASY · O(n log n)
- Merge Triplets to Form Target TripletMEDIUM · O(n)
- Minimum Number of Arrows to Burst BalloonsMEDIUM · O(n log n)
- Monotone Increasing DigitsMEDIUM · O(d)
- Partition LabelsMEDIUM · O(n)
- Queue Reconstruction by HeightMEDIUM · O(n^2)
- Reorganize StringMEDIUM · O(n log k)
- Task SchedulerMEDIUM · O(N)
- Valid Parenthesis StringMEDIUM · O(n)
- Wiggle SubsequenceMEDIUM · O(n)
See the full solution
The complete approach, reference solutions in 5 languages, and a step-by-step visualization — then add this problem to your spaced-repetition schedule.
Start free →