Practice SetLesson 221 min read

Greedy Algorithms — Practice Problems

November 05, 2026

// How to use this set

Work these in order: easy (Assign Cookies) → medium (Jump Game, Jump Game II, Gas Station, Partition Labels, Task Scheduler, Hand of Straights, Remove Covered Intervals, Valid Parenthesis String, Merge Triplets to Form Target) → hard (Candy). For each, name the greedy choice and convince yourself it is safe before coding. Every solution below was run and tested.

Eleven problems that drill the greedy pattern from Lesson 22. The real exercise is articulating why the greedy choice is safe — do that out loud for each one. Each solution here was actually run and tested.

How to practise. For each problem, state the greedy rule in one sentence (“always take the earliest-finishing…”, “track the furthest reach…”) and give a one-line reason it can’t lose. If you can’t justify it, that’s a signal the problem might need DP — check a small adversarial case before trusting the code.

The 11 problems

  1. 1Assign Cookies (LeetCode 455)EasyFeed as many children as possible: sort both lists and give each child the smallest cookie that works.arrow_forward
  2. 2Jump Game (LeetCode 55)MediumCan you reach the last index? Track the furthest index reachable so far; if you step past it, you're stuck.arrow_forward
  3. 3Jump Game II (LeetCode 45)MediumFewest jumps to reach the last index: treat each jump as a BFS level and greedily extend the furthest reach.arrow_forward
  4. 4Gas Station (LeetCode 134)MediumFind where a circular trip can start: check total gas, then reset the start whenever the tank goes negative.arrow_forward
  5. 5Partition Labels (LeetCode 763)MediumSplit a string into most parts, no letter in two: extend each part to its letters' last occurrence.arrow_forward
  6. 6Task Scheduler (LeetCode 621)MediumFewest CPU slots to run tasks with a cooldown: the most frequent task builds the frame, the rest fill gaps.arrow_forward
  7. 7Hand of Straights (LeetCode 846)MediumSplit cards into runs of consecutive values: the smallest card left must start a run, so count and consume.arrow_forward
  8. 8Remove Covered Intervals (LeetCode 1288)MediumCount intervals not inside another: sort by start, longer first on ties, and keep only ends that beat the max.arrow_forward
  9. 9Valid Parenthesis String (LeetCode 678)MediumCheck brackets where '*' can be '(', ')' or empty: track the min and max possible open count.arrow_forward
  10. 10Merge Triplets to Form Target Triplet (LeetCode 1899)MediumCan element-wise max merges build the target? Skip triplets that overshoot, then check every position is hit.arrow_forward
  11. 11Candy (LeetCode 135)HardFewest candies so higher ratings beat neighbours: sweep left-to-right, then right-to-left with max.arrow_forward