Master every algorithm pattern from foundation to god tier. Organized by the ecchito tier system with real problems to grind for each pattern.
Competitive programming is different from interview prep. Interviews test if you can apply known patterns under pressure. CP tests if you can combine patterns creatively, optimize to tight constraints, and think under time limits. This roadmap prepares you for both.
| Tier | Description | Target |
|---|---|---|
| Regular | Core patterns that appear in 80% of problems | Master first -- these are your bread and butter |
| Magical | Intermediate algorithms for harder contest problems | Codeforces 1400-1800 rating range |
| Rare | Advanced techniques for Div 1 / hard problems | Codeforces 1800-2100 rating range |
| Epic | Expert-level algorithms for top competitive programmers | Codeforces 2100-2400 rating range |
| Legendary | God-tier algorithms -- rarely needed but devastating when they are | Codeforces 2400+ / IOI / ICPC |
Speed matters in contests. Once you understand a pattern, practice implementing it fast. Time yourself. A contest-ready programmer can code BFS, DFS, Dijkstra, and basic DP from scratch in under 5 minutes each.
These 22 patterns form the core of competitive programming. You will use them in almost every contest. Master all of these before moving to Magical tier.
Scan from both ends or same direction to find pairs, partition arrays, or detect conditions in O(n).
Study: Patterns → Two Pointers
| Problem | Platform | Difficulty |
|---|---|---|
| Two Sum II - Input Array Is Sorted (#167) | LeetCode | Medium |
| 3Sum (#15) | LeetCode | Medium |
| Container With Most Water (#11) | LeetCode | Medium |
| Trapping Rain Water (#42) | LeetCode | Hard |
| Move Zeroes (#283) | LeetCode | Easy |
O(1) lookups for frequency counting, grouping, and finding complements.
Study: Hash Maps & Sets | Patterns → HashMap
| Problem | Platform | Difficulty |
|---|---|---|
| Two Sum (#1) | LeetCode | Easy |
| Group Anagrams (#49) | LeetCode | Medium |
| Subarray Sum Equals K (#560) | LeetCode | Medium |
| Longest Consecutive Sequence (#128) | LeetCode | Medium |
| Valid Anagram (#242) | LeetCode | Easy |
Halve the search space each step. Works on sorted arrays and monotonic functions (binary search on the answer).
Study: Patterns → Binary Search
| Problem | Platform | Difficulty |
|---|---|---|
| Binary Search (#704) | LeetCode | Easy |
| Search in Rotated Sorted Array (#33) | LeetCode | Medium |
| Find Minimum in Rotated Sorted Array (#153) | LeetCode | Medium |
| Koko Eating Bananas (#875) | LeetCode | Medium |
| Median of Two Sorted Arrays (#4) | LeetCode | Hard |
Maintain a window over contiguous elements. Fixed size or variable size (expand right, shrink left).
Study: Patterns → Sliding Window
| Problem | Platform | Difficulty |
|---|---|---|
| Best Time to Buy and Sell Stock (#121) | LeetCode | Easy |
| Longest Substring Without Repeating Characters (#3) | LeetCode | Medium |
| Minimum Window Substring (#76) | LeetCode | Hard |
| Sliding Window Maximum (#239) | LeetCode | Hard |
| Permutation in String (#567) | LeetCode | Medium |
Find the maximum sum contiguous subarray in O(n). The foundation of many DP problems.
Study: Patterns → Kadane's | Dynamic Programming
| Problem | Platform | Difficulty |
|---|---|---|
| Maximum Subarray (#53) | LeetCode | Medium |
| Maximum Product Subarray (#152) | LeetCode | Medium |
| Maximum Sum Circular Subarray (#918) | LeetCode | Medium |
| Best Time to Buy and Sell Stock (#121) | LeetCode | Easy |
Sort intervals by start time, then merge overlapping ones. Foundation for all interval problems.
Study: Patterns → Intervals
| Problem | Platform | Difficulty |
|---|---|---|
| Merge Intervals (#56) | LeetCode | Medium |
| Insert Interval (#57) | LeetCode | Medium |
| Non-overlapping Intervals (#435) | LeetCode | Medium |
| Meeting Rooms II (#253) | LeetCode | Medium |
Precompute cumulative sums to answer range sum queries in O(1). Combine with hashmap for subarray sum problems.
Study: Patterns → Prefix Sum
| Problem | Platform | Difficulty |
|---|---|---|
| Range Sum Query - Immutable (#303) | LeetCode | Easy |
| Subarray Sum Equals K (#560) | LeetCode | Medium |
| Product of Array Except Self (#238) | LeetCode | Medium |
| Contiguous Array (#525) | LeetCode | Medium |
Use heaps (priority queues) or quickselect to find the K largest/smallest/most frequent elements.
Study: Advanced Topics → Heaps | Patterns → Top K
| Problem | Platform | Difficulty |
|---|---|---|
| Kth Largest Element in an Array (#215) | LeetCode | Medium |
| Top K Frequent Elements (#347) | LeetCode | Medium |
| K Closest Points to Origin (#973) | LeetCode | Medium |
| Find Median from Data Stream (#295) | LeetCode | Hard |
| Merge K Sorted Lists (#23) | LeetCode | Hard |
Maintain a stack/deque in sorted order to find next greater/smaller elements or sliding window extremes in O(n).
Study: Patterns → Monotonic Stack | Advanced → Monotonic Queue
| Problem | Platform | Difficulty |
|---|---|---|
| Daily Temperatures (#739) | LeetCode | Medium |
| Next Greater Element I (#496) | LeetCode | Easy |
| Largest Rectangle in Histogram (#84) | LeetCode | Hard |
| Sliding Window Maximum (#239) | LeetCode | Hard |
Level-by-level exploration. Guarantees shortest path in unweighted graphs. Use a queue.
Study: Patterns → BFS | Graphs
| Problem | Platform | Difficulty |
|---|---|---|
| Number of Islands (#200) | LeetCode | Medium |
| Binary Tree Level Order Traversal (#102) | LeetCode | Medium |
| Rotting Oranges (#994) | LeetCode | Medium |
| Word Ladder (#127) | LeetCode | Hard |
| Open the Lock (#752) | LeetCode | Medium |
Start BFS from multiple sources simultaneously. Used for "spread" problems (fire, infection, distance from nearest).
Study: Patterns → BFS (Multi-Source)
| Problem | Platform | Difficulty |
|---|---|---|
| Rotting Oranges (#994) | LeetCode | Medium |
| 01 Matrix (#542) | LeetCode | Medium |
| Walls and Gates (#286) | LeetCode | Medium |
| Shortest Bridge (#934) | LeetCode | Medium |
Order vertices of a DAG so every edge goes from earlier to later. Kahn's (BFS with indegree) or DFS post-order.
Study: Graphs → Topological Sort | Patterns → Topo Sort
| Problem | Platform | Difficulty |
|---|---|---|
| Course Schedule (#207) | LeetCode | Medium |
| Course Schedule II (#210) | LeetCode | Medium |
| Alien Dictionary (#269) | LeetCode | Hard |
| Parallel Courses (#1136) | LeetCode | Medium |
Shortest path in weighted graphs with non-negative edges. Uses a min-heap (priority queue).
Study: Graphs → Dijkstra | Patterns → Dijkstra
| Problem | Platform | Difficulty |
|---|---|---|
| Network Delay Time (#743) | LeetCode | Medium |
| Cheapest Flights Within K Stops (#787) | LeetCode | Medium |
| Path with Maximum Probability (#1514) | LeetCode | Medium |
| Swim in Rising Water (#778) | LeetCode | Hard |
Go as deep as possible before backtracking. Recursion or explicit stack. Used for trees, graphs, connectivity.
Study: Patterns → DFS | Graphs
| Problem | Platform | Difficulty |
|---|---|---|
| Number of Islands (#200) | LeetCode | Medium |
| Max Area of Island (#695) | LeetCode | Medium |
| Clone Graph (#133) | LeetCode | Medium |
| Pacific Atlantic Water Flow (#417) | LeetCode | Medium |
| Number of Connected Components (#323) | LeetCode | Medium |
2-color the graph using BFS/DFS. If any edge connects same-color nodes, it's not bipartite.
Study: Patterns → Bipartite
| Problem | Platform | Difficulty |
|---|---|---|
| Is Graph Bipartite? (#785) | LeetCode | Medium |
| Possible Bipartition (#886) | LeetCode | Medium |
| Codeforces: Bipartiteness (862B) | Codeforces | 1400 |
Choose-explore-unchoose. Generate all permutations, combinations, subsets, or valid configurations.
Study: Patterns → DFS & Backtracking
| Problem | Platform | Difficulty |
|---|---|---|
| Subsets (#78) | LeetCode | Medium |
| Permutations (#46) | LeetCode | Medium |
| Combination Sum (#39) | LeetCode | Medium |
| Word Search (#79) | LeetCode | Medium |
| N-Queens (#51) | LeetCode | Hard |
Find all primes up to N in O(N log log N). Essential for number theory problems in CP.
Study: Advanced → Sieve | Patterns → Sieve
| Problem | Platform | Difficulty |
|---|---|---|
| Count Primes (#204) | LeetCode | Medium |
| Four Divisors (#1390) | LeetCode | Medium |
| Closest Prime Numbers in Range (#2523) | LeetCode | Medium |
| CSES: Counting Divisors | CSES | Medium |
Convert intervals to +1/-1 events, sort, and sweep to find peak overlaps, skylines, or coverage.
Study: Patterns → Sweep Line
| Problem | Platform | Difficulty |
|---|---|---|
| Meeting Rooms II (#253) | LeetCode | Medium |
| The Skyline Problem (#218) | LeetCode | Hard |
| My Calendar I (#729) | LeetCode | Medium |
| My Calendar III (#732) | LeetCode | Hard |
Break problems into overlapping subproblems. Memoize (top-down) or tabulate (bottom-up). The most important pattern in CP.
Study: Dynamic Programming | Patterns → DP
| Problem | Platform | Difficulty |
|---|---|---|
| Climbing Stairs (#70) | LeetCode | Easy |
| House Robber (#198) | LeetCode | Medium |
| Coin Change (#322) | LeetCode | Medium |
| Unique Paths (#62) | LeetCode | Medium |
| CSES: Dice Combinations | CSES | Easy |
Problems where dp[i] depends on dp[i-1] and dp[i-2] (or similar small lookback). Often optimizable to O(1) space.
Study: DP → Fibonacci
| Problem | Platform | Difficulty |
|---|---|---|
| Fibonacci Number (#509) | LeetCode | Easy |
| Climbing Stairs (#70) | LeetCode | Easy |
| House Robber (#198) | LeetCode | Medium |
| Decode Ways (#91) | LeetCode | Medium |
For each item: include it or skip it. Classic 0/1 decision framework. dp[i][w] = best value using items 0..i with capacity w.
Study: DP → 0/1 Knapsack
| Problem | Platform | Difficulty |
|---|---|---|
| Partition Equal Subset Sum (#416) | LeetCode | Medium |
| Target Sum (#494) | LeetCode | Medium |
| Last Stone Weight II (#1049) | LeetCode | Medium |
| Ones and Zeroes (#474) | LeetCode | Medium |
| CSES: Book Shop | CSES | Medium |
Classic O(n^2) DP: dp[i] = length of LIS ending at index i. For each i, check all j < i where arr[j] < arr[i].
Study: DP → LIS | Patterns → NlogN LIS
| Problem | Platform | Difficulty |
|---|---|---|
| Longest Increasing Subsequence (#300) | LeetCode | Medium |
| Number of Longest Increasing Subsequence (#673) | LeetCode | Medium |
| Russian Doll Envelopes (#354) | LeetCode | Hard |
| Longest String Chain (#1048) | LeetCode | Medium |
Before moving to Magical, you should be able to:
These algorithms appear in harder contest problems and are the bridge between "solid" and "strong" competitive programmers.
All-pairs shortest path in O(V^3). Simple triple nested loop. Works with negative edges (no negative cycles).
Study: Patterns → Floyd Warshall & Bellman Ford
| Problem | Platform | Difficulty |
|---|---|---|
| Find the City With the Smallest Number of Neighbors (#1334) | LeetCode | Medium |
| Shortest Path Visiting All Nodes (#847) | LeetCode | Hard |
| CSES: Shortest Routes II | CSES | Medium |
| Codeforces: Greg and Graph (295B) | Codeforces | 1700 |
Use a bitmask to represent subsets. dp[mask] = answer for the subset represented by mask. O(2^n * n).
Study: Patterns → Bitmask DP
| Problem | Platform | Difficulty |
|---|---|---|
| Partition to K Equal Sum Subsets (#698) | LeetCode | Medium |
| Shortest Path Visiting All Nodes (#847) | LeetCode | Hard |
| Maximum Students Taking Exam (#1349) | LeetCode | Hard |
| CSES: Hamiltonian Flights | CSES | Hard |
| Codeforces: Matching Burnside (to practice bitmask enumeration) | Codeforces | 1800 |
Single-source shortest path that handles negative weights. Relax all edges V-1 times. Detects negative cycles.
Study: Patterns → Floyd Warshall & Bellman Ford
| Problem | Platform | Difficulty |
|---|---|---|
| Cheapest Flights Within K Stops (#787) | LeetCode | Medium |
| Network Delay Time (#743) | LeetCode | Medium |
| CSES: Cycle Finding | CSES | Medium |
| CSES: High Score (negative cycle detection) | CSES | Hard |
Optimize LIS from O(n^2) to O(n log n) using binary search on a "tails" array. Essential for large inputs in CP.
Study: Patterns → NlogN LIS
| Problem | Platform | Difficulty |
|---|---|---|
| Longest Increasing Subsequence (#300) | LeetCode | Medium |
| Russian Doll Envelopes (#354) | LeetCode | Hard |
| Maximum Length of Pair Chain (#646) | LeetCode | Medium |
| CSES: Towers | CSES | Medium |
These show up in Div 1 problems and harder LeetCode Hards. Learning these separates you from most competitive programmers.
Count numbers in a range [L, R] satisfying digit constraints. Build the number digit by digit, tracking whether you're still "tight" to the upper bound.
Study: Patterns → Digit DP
| Problem | Platform | Difficulty |
|---|---|---|
| Numbers At Most N Given Digit Set (#902) | LeetCode | Hard |
| Count of Integers (#2719) | LeetCode | Hard |
| Non-negative Integers without Consecutive Ones (#600) | LeetCode | Hard |
| CSES: Counting Numbers | CSES | Hard |
| Codeforces: Magic Numbers (628D) | Codeforces | 2200 |
Supports point updates and prefix sum queries in O(log n). Simpler to implement than segment tree. Uses bit manipulation to navigate the tree.
Study: Patterns → Fenwick Tree
| Problem | Platform | Difficulty |
|---|---|---|
| Range Sum Query - Mutable (#307) | LeetCode | Medium |
| Count of Smaller Numbers After Self (#315) | LeetCode | Hard |
| Reverse Pairs (#493) | LeetCode | Hard |
| CSES: Dynamic Range Sum Queries | CSES | Medium |
| CSES: Nested Ranges Count | CSES | Hard |
Visit every EDGE exactly once. Hierholzer's algorithm. Exists iff 0 or 2 vertices have odd degree (undirected) or in-degree matches out-degree (directed).
Study: Patterns → Eulerian Paths
| Problem | Platform | Difficulty |
|---|---|---|
| Reconstruct Itinerary (#332) | LeetCode | Hard |
| Valid Arrangement of Pairs (#2097) | LeetCode | Hard |
| Cracking the Safe (#753) | LeetCode | Hard |
| CSES: Mail Delivery | CSES | Hard |
Expert-level data structures and string algorithms. These unlock the hardest contest problems.
Find pattern in text in O(n + m) using a failure/prefix function. No backtracking in the text. Essential for string matching in CP.
Study: Patterns → KMP & Rolling Hash
| Problem | Platform | Difficulty |
|---|---|---|
| Find the Index of the First Occurrence (#28) | LeetCode | Easy |
| Repeated Substring Pattern (#459) | LeetCode | Easy |
| Shortest Palindrome (#214) | LeetCode | Hard |
| CSES: String Matching | CSES | Medium |
| Codeforces: Password (126B) | Codeforces | 1700 |
Range queries and range/point updates in O(log n). Supports sum, min, max, GCD, and more. Lazy propagation for range updates.
Study: Patterns → Segment Tree | Advanced → Segment Tree
| Problem | Platform | Difficulty |
|---|---|---|
| Range Sum Query - Mutable (#307) | LeetCode | Medium |
| Count of Range Sum (#327) | LeetCode | Hard |
| Falling Squares (#699) | LeetCode | Hard |
| CSES: Dynamic Range Minimum Queries | CSES | Medium |
| CSES: Range Update Queries | CSES | Medium |
| Codeforces: Sereja and Brackets (380C) | Codeforces | 2000 |
Hash substrings in O(1) after O(n) preprocessing. Compare substrings without character-by-character comparison. Great for pattern matching and palindrome detection.
Study: Patterns → KMP & Rolling Hash
| Problem | Platform | Difficulty |
|---|---|---|
| Longest Duplicate Substring (#1044) | LeetCode | Hard |
| Distinct Echo Substrings (#1316) | LeetCode | Hard |
| Longest Happy Prefix (#1392) | LeetCode | Hard |
| CSES: String Hashing | CSES | Medium |
The final boss. FFT is rarely needed but when it is, nothing else will work. This is what separates the top 1%.
Multiply two polynomials in O(n log n) instead of O(n^2). Also used for large number multiplication and convolution problems. NTT (Number Theoretic Transform) is the modular arithmetic variant.
Study: Patterns → FFT
| Problem | Platform | Difficulty |
|---|---|---|
| Multiply Strings (#43) (motivational -- FFT overkill here) | LeetCode | Medium |
| CSES: Polynomial Multiplication | CSES | Hard |
| Codeforces: Yet Another Counting Problem (practice convolution) | Codeforces | 2300+ |
| AtCoder: Convolution (practice problem from AtCoder Library) | AtCoder | Hard |
FFT appears in maybe 1-2% of contest problems. Don't grind this until you're comfortable with everything above. When you get here, you're already in the top tier of competitive programmers.
| Platform | Best For | How to Use |
|---|---|---|
| LeetCode | Pattern practice, interviews, weekly contests | Filter by topic/difficulty. Do Weekly and Biweekly contests every week. Track your contest rating. |
| Codeforces | True competitive programming, rating system, editorials | Start with Div 3/4 contests. Work up to Div 2. Upsolve every problem you couldn't solve during contest. Virtual contests to practice under time pressure. |
| AtCoder | Clean problems, great for beginners, educational contests | ABC (AtCoder Beginner Contest) for practice. Problems A-D are Regular tier, E-F are Magical/Rare. Very well-structured difficulty curve. |
| CSES Problem Set | Structured topic-by-topic practice (300 problems) | Go section by section. Every problem teaches a specific technique. The best structured problem set available. Covers Regular through Rare tiers. |
| USACO | Algorithm olympiad problems, longer thinking problems | Past contest problems sorted by difficulty (Bronze/Silver/Gold/Platinum). Great for deeper algorithmic thinking. |
| Kattis | University-level CP problems, ICPC practice | Problems from real ICPC regionals and other contests. Difficulty ratings from 1-10. Great for C++ practice. |
| HackerRank | Beginner-friendly, language-specific tracks | Good for warming up in a new language (C++, Python). Problem Solving track covers basics well. |
| Project Euler | Math + programming problems | Pure math-heavy problems. Great for building the math intuition that CP requires. Start from problem 1. |
| DMOJ | Canadian computing olympiad problems, great judges | Clean problem archive. Good for practicing with strict time limits. Supports C++, Python, Java, Go. |
C++ is the king of CP. It's the fastest, has the best STL (Standard Template Library), and 95% of top competitive programmers use it. Here's your path:
bits/stdc++.h, ios_base::sync_with_stdio(false), cin.tie(NULL), sort(), lower_bound(), upper_bound(), set, map, priority_queue, pair, vector, bitset.template.cpp file with your standard includes, fast I/O, and common macros. Use it for every contest.
Month 1-2: LeetCode Easy/Medium by pattern (Regular tier) + CSES Introductory/Sorting sections
Month 3-4: LeetCode Medium/Hard + Codeforces Div 3/4 contests + CSES Graph/DP sections
Month 5-6: Codeforces Div 2 contests + AtCoder ABC + Magical tier algorithms
Month 7+: Codeforces Div 2/1 + Rare/Epic algorithms + USACO Gold/Platinum
Competitive programming isn't just for practice -- there are real competitions with real prizes. Here's where you can compete and potentially earn money.
| Contest | Frequency | Prizes | Notes |
|---|---|---|---|
| LeetCode Weekly Contest | Every Sunday | LeetCoins (redeemable for swag/premium) | Best place to start. 4 problems, 90 minutes. Track your rating growth. |
| LeetCode Biweekly Contest | Every other Saturday | LeetCoins | Same format as Weekly. Double your contest practice. |
| Codeforces Rounds | 2-3 times/week | Rating (your rank in the global CP community) | The heartbeat of competitive programming. Div 3/4 for beginners, Div 2 for intermediate, Div 1 for advanced. |
| AtCoder Beginner Contest (ABC) | Weekly (Saturdays) | Rating | Cleanest problems in CP. Great for building fundamentals. |
| Competition | When | Prize Pool | Requirements |
|---|---|---|---|
| Google Code Jam (now Coding Competitions) | Annual (check Google's site for current format) | $15,000+ for top finishers | Open to all. Online rounds qualify you for later stages. Great resume item. |
| Meta Hacker Cup | Annual (usually Oct-Nov) | $20,000+ total prizes | Open to all. Online qualification rounds. Problems range from easy to insane. |
| ICPC (International Collegiate Programming Contest) | Annual | Scholarships, trophies, job offers | Must be enrolled in university. Teams of 3. The most prestigious CP competition. Regional qualifiers lead to World Finals. |
| Topcoder Open (TCO) | Annual | $25,000+ in prizes | Open to all Topcoder members. Algorithm track has online rounds leading to onsite finals. |
| Codeforces Global Rounds | Several per year | Prizes for top-rated participants | Open to all. Higher prize pools than regular rounds. |
| AtCoder Grand Contest (AGC) | Periodic | Cash prizes for top finishers | Harder problems. Need a solid rating to compete effectively. |
| Reply Code Challenge | Annual (March) | Cash prizes + tech gadgets | Team contest (2-4 people). Fun optimization problems. Good entry-level competition. |
| Advent of Code | December (25 days) | No cash, but leaderboard bragging rights + community | Daily puzzles in December. Great for building consistency and having fun. Solve in any language. |
| CodeChef Long/Short Contests | Monthly | Laddus (redeemable for cash/prizes) | Long contests (10 days) are great for learning. Short contests test speed. |
| HackerRank Contests | Various | Cash prizes, job opportunities | Company-sponsored contests often have significant prizes. Check their contest page regularly. |
Short term: Focus on LeetCode Weekly + Codeforces Div 3/4 to build rating and speed.
Medium term: Enter Meta Hacker Cup, Google competitions, and Codeforces Global Rounds.
Long term: If you're in university, ICPC is the ultimate goal. If not, Topcoder Open and major platform finals.
The money comes when you're consistently solving 4+ problems in contests. Get your Codeforces rating to 1600+ and you'll start placing in prize ranges.
Consistency beats intensity. Here's a sustainable schedule for getting cracked at CP.
| Day | Focus | Time | Activity |
|---|---|---|---|
| Monday | New Pattern | 1.5-2 hrs | Learn one new algorithm/pattern. Read theory, understand the template, code it from scratch. |
| Tuesday | Practice | 1.5-2 hrs | Solve 3-4 problems using Monday's pattern. Start easy, increase difficulty. |
| Wednesday | Mixed Practice | 1.5-2 hrs | Solve 3-4 random problems (no topic filter). Practice pattern recognition. |
| Thursday | Hard Problems | 1.5-2 hrs | Attempt 1-2 hard problems. Spend 30 min each, then read editorials if stuck. |
| Friday | Review | 1 hr | Re-solve problems you got wrong this week without looking at solutions. |
| Saturday | Contest | 2-2.5 hrs | LeetCode Weekly Contest OR Codeforces Round (virtual or live). |
| Sunday | Upsolve | 1.5 hrs | Solve the contest problems you couldn't solve. Read editorials for every unsolved problem. |
For every problem:
Don't spend 3 hours on one problem hoping for a breakthrough. That's not practice, that's stubbornness. Read the editorial after 30 minutes, learn the technique, and move on. You'll get faster with practice, not with suffering.
Competitive programming is a marathon, not a sprint. The people who get cracked are the ones who show up every day, not the ones who grind 12 hours once a week. Be consistent. Trust the process. You will get there.