Greedy Patterns — DSA Pattern
The Greedy Patterns pattern applies when you need interval scheduling, jump games, stock trading, and task scheduling. Its time complexity is O(n) for a single greedy pass; O(n log n) when the input must be sorted first and space complexity O(1) to O(n). It is used in 14 problems on Thita, including Assign Cookies, Candy and Distant Barcodes. Common variations are Sorting Based and Buy/Sell Stock.
Master greedy algorithms including interval scheduling, jump games, stock trading, and task scheduling. Make locally optimal choices for global optimization.
Greedy Patterns is pattern 10 of 16 in the Thita.ai DSA course. It covers interval scheduling, jump games, stock trading, and task scheduling, split into 7 subpatterns and about 3 hours of study. It is one of the interview-critical patterns, so it is worth covering before your first onsite.
Subpatterns of Greedy Patterns
Each subpattern below has its own theory page and problem set. They are listed in the order the course teaches them.
- Jump Game Reachability/Minimization — Solve jump game problems using greedy approach. Check reachability and find minimum jumps. (core technique)
- Interval Merging/Scheduling — Master interval problems including merge intervals, insert interval, and non-overlapping intervals. (core technique)
- Sorting Based — Solve greedy problems that require sorting as preprocessing step for optimal solutions. (important variation)
- Buy/Sell Stock — Optimize stock trading with greedy strategy. Single transaction and multiple transactions. (important variation)
- Task Scheduling (Frequency Based) — Schedule tasks with cooldown using frequency-based greedy approach. (depth topic)
- Line Sweep — Master the line sweep technique for interval and geometric problems. Process events in sorted order for overlap counting, skyline, and meeting room problems. (depth topic)
- Gas Station Circuit — Find the starting gas station index to complete a circular route using greedy approach. (depth topic)
How to practise Greedy Patterns on Thita.ai
Read the theory for a subpattern, then solve its problems in the browser editor. Your solution runs against the problem's test cases, and the AI coach gives a hint on the technique you are missing rather than the finished answer. Progress is tracked per subpattern, so the tracker shows which of the 7 Greedy Patterns subpatterns you have covered. Topics covered here include greedy algorithm, greedy patterns, interval scheduling, jump game, stock trading, task scheduling, greedy optimization, leetcode greedy.
Related DSA patterns
- Tree Traversal Patterns (DFS & BFS) — Preorder, inorder, level order traversal, LCA, and serialization.
- Heap (Priority Queue) Patterns — Top K elements, K-way merge, two heaps for median, and scheduling.
- Backtracking Patterns — Subsets, permutations, combinations, N-Queens, and word search.
- Dynamic Programming (DP) Patterns — Fibonacci, Kadane, knapsack, LCS, LIS, edit distance, grid paths, and word break.
- Graph Traversal Patterns (DFS & BFS) — DFS/BFS traversal, topological sort, shortest paths, Union-Find, and MST.
- All 16 DSA patterns
- The DSA patterns sheet
- Coding practice