Greedy [mp]
Micro pattern¶
Description¶
Make locally justified choices that preserve a globally valid or optimal solution.
Problems¶
Take every profitable contribution¶
Collect independent positive gains when each can safely contribute.
- 122. Best Time to Buy and Sell Stock II (Top Easy)
- 188. Best Time to Buy and Sell Stock IV (Dynamic Programming)
Maintain the best reachable or smallest state¶
Discard dominated states while retaining those most useful for future extensions.
- 55. Jump Game (Top Medium)
- 300. Longest Increasing Subsequence (Top Medium)
- 334. Increasing Triplet Subsequence (Top Medium)
- 354. Russian Doll Envelopes (Dynamic Programming)
- 1964. Find the Longest Valid Obstacle Course at Each Position (Dynamic Programming)
Candidate cancellation¶
Cancel competing occurrences to retain possible frequent candidates.
- 169. Majority Element (Top Medium)
- 229. Majority Element II (Google Prep)
Greedy construction¶
Process items in an order that makes each local placement safe.
- 1042. Flower Planting With No Adjacent (Google Prep)
- 1221. Split a String in Balanced Strings (Google Prep)
- 406. Queue Reconstruction by Height (Top Hard)
- 646. Maximum Length of Pair Chain (Dynamic Programming)
Eliminate a dominated boundary¶
Move the boundary whose value limits improvement within the remaining region.
- 11. Container With Most Water (Top Hard)
Reuse the latest wildcard¶
Return to the latest unrestricted wildcard when a later match fails.
- 44. Wildcard Matching (Top Hard)