Greedy coding problems
Greedy problems pick the locally best move and prove it never hurts: intervals, scheduling, coin and jump games. Practise spotting when greedy works and when it needs dynamic programming instead.
41 problems: 9 easy, 26 medium, 6 hard. Free to read; a free account solves them and earns XP and Aura.
- Count Elements Greater Than PreviousPractice · +10 XP · greedy, arrays, loopseasy
- Find Maximum ValuePractice · +10 XP · greedy, simple iterationeasy
- Maximize Non-Negative SumPractice · +10 XP · greedy, arrayseasy
- Maximum Odd SumPractice · +10 XP · greedy, iteration, basiceasy
- Maximum Sum of Adjacent ElementsPractice · +10 XP · greedy, dynamic programmingeasy
- Minimum Absolute DifferencePractice · +10 XP · greedy, sorting, arrayseasy
- Minimum Cost to SortPractice · +10 XP · greedy, sorting, bubble sorteasy
- Smallest ElementPractice · +10 XP · greedy, arrays, iterationeasy
- Sum of Positive NumbersPractice · +10 XP · greedy, loopseasy
- Distinct Element Sum with Minimum CostPractice · +20 XP · heaps, hash map, greedymedium
- Distinct Elements CountPractice · +20 XP · greedy, hash map, countingmedium
- Distinct Elements with Minimum Total CostPractice · +20 XP · heaps, hash set, greedymedium
- Longest Alternating SubsequencePractice · +20 XP · dynamic programming, greedymedium
- Longest Subarray with Constant DifferencePractice · +20 XP · two pointers, greedy, arraysmedium
- Longest Subarray with Limited DifferencePractice · +20 XP · two pointers, sliding window, greedymedium
- Max Consecutive SumPractice · +20 XP · two pointers, dynamic programming, greedymedium
- Maximize Distinct Elements After OperationsPractice · +20 XP · heaps, greedy, data structuresmedium
- Maximize Minimum DifferencePractice · +20 XP · binary search, greedymedium
- Maximize Non-overlapping IntervalsPractice · +20 XP · greedy, sortingmedium
- Maximum Non-overlapping IntervalsPractice · +20 XP · greedy, sorting, intervalsmedium
- Maximum Sum of Consecutive SubsegmentsPractice · +20 XP · dynamic programming, array, greedymedium
- Maximum Sum of Non-Adjacent Elements in a Circular ArrayPractice · +20 XP · dynamic programming, greedy, arraysmedium
- Maximum Sum of Non-Adjacent SubarraysPractice · +20 XP · dynamic programming, arrays, greedymedium
- Maximum Sum of Non-Overlapping Positive SubarraysPractice · +20 XP · stack, dynamic programming, greedymedium
- Maximum Sum of Non-Overlapping SegmentsPractice · +20 XP · greedy, dynamic programming, sortingmedium
- Maximum Sum of Non-overlapping SubarraysPractice · +20 XP · greedy, dynamic programming, prefix sumsmedium
- Maximum Sum of Non-Overlapping SubsegmentsPractice · +20 XP · dynamic programming, greedymedium
- Minimize Maximum DifferencePractice · +20 XP · binary search, greedy, sortingmedium
- Minimize Maximum Difference in PairsPractice · +20 XP · greedy, sorting, two pointersmedium
- Minimize Maximum Segment SumPractice · +20 XP · binary search, greedymedium
- Minimum Cost to Make All EqualPractice · +20 XP · binary search, greedymedium
- Minimum Maximum DifferencePractice · +20 XP · binary search, greedymedium
- Minimum Maximum Height DifferencePractice · +20 XP · binary search, greedymedium
- Minimum Operations to Make Array SortedPractice · +20 XP · greedy, sorting, arraysmedium
- Process Tasks by DeadlinePractice · +20 XP · heaps, scheduling, greedymedium
- Longest Increasing Subsequence on a PermutationPractice · +30 XP · recursion, dynamic programming, greedyhard
- Longest Increasing Subsequence with Stack ConstraintPractice · +30 XP · stack, dynamic programming, greedyhard
- Maximum Sum of Non-Overlapping IntervalsPractice · +30 XP · greedy, dynamic programming, interval schedulinghard
- Minimize Maximum Difference of Elements in IntervalsPractice · +30 XP · heaps, sliding window, greedyhard
- Minimize Maximum Difference of Grouped ElementsPractice · +30 XP · binary search, greedy, prefix sumshard
- Minimum Maximum SumPractice · +30 XP · binary search, divide and conquer, greedyhard
Solve these free. Get paid in XP and Aura.
One tap with Google, no card. Every first accepted solve pays XP for the leaderboards and Aura for real goodies.
Other topics
Hash Map and Hashing101Arrays88Prefix Sums64SQL and Databases64Beginner Coding Problems60Graphs, BFS and DFS45Sliding Window39Dynamic Programming37Sorting36Math and Number Theory36Strings35Two Pointers35Stack29Binary Search25Simulation25Recursion22Linked List20Trees20Heap and Priority Queue18Matrix and Grid18Bit Manipulation18Queue and Deque16