On This Page

1. How to Use This Roadmap 2. Regular Algorithms (Foundation) 3. Magical Algorithms (Intermediate) 4. Rare Algorithms (Advanced) 5. Epic Algorithms (Expert) 6. Legendary Algorithms (God Tier) 7. Platforms & Resources 8. Weekly Training Schedule

1. How to Use This Roadmap

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.

The Tier System

TierDescriptionTarget
RegularCore patterns that appear in 80% of problemsMaster first -- these are your bread and butter
MagicalIntermediate algorithms for harder contest problemsCodeforces 1400-1800 rating range
RareAdvanced techniques for Div 1 / hard problemsCodeforces 1800-2100 rating range
EpicExpert-level algorithms for top competitive programmersCodeforces 2100-2400 rating range
LegendaryGod-tier algorithms -- rarely needed but devastating when they areCodeforces 2400+ / IOI / ICPC

The Approach

Pro Tip

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.

2. Regular Algorithms Foundation

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.

Two Pointer

Scan from both ends or same direction to find pairs, partition arrays, or detect conditions in O(n).

ProblemPlatformDifficulty
Two Sum II - Input Array Is Sorted (#167)LeetCodeMedium
3Sum (#15)LeetCodeMedium
Container With Most Water (#11)LeetCodeMedium
Trapping Rain Water (#42)LeetCodeHard
Move Zeroes (#283)LeetCodeEasy

HashMap

O(1) lookups for frequency counting, grouping, and finding complements.

ProblemPlatformDifficulty
Two Sum (#1)LeetCodeEasy
Group Anagrams (#49)LeetCodeMedium
Subarray Sum Equals K (#560)LeetCodeMedium
Longest Consecutive Sequence (#128)LeetCodeMedium
Valid Anagram (#242)LeetCodeEasy

Binary Search

Halve the search space each step. Works on sorted arrays and monotonic functions (binary search on the answer).

ProblemPlatformDifficulty
Binary Search (#704)LeetCodeEasy
Search in Rotated Sorted Array (#33)LeetCodeMedium
Find Minimum in Rotated Sorted Array (#153)LeetCodeMedium
Koko Eating Bananas (#875)LeetCodeMedium
Median of Two Sorted Arrays (#4)LeetCodeHard

Sliding Window

Maintain a window over contiguous elements. Fixed size or variable size (expand right, shrink left).

ProblemPlatformDifficulty
Best Time to Buy and Sell Stock (#121)LeetCodeEasy
Longest Substring Without Repeating Characters (#3)LeetCodeMedium
Minimum Window Substring (#76)LeetCodeHard
Sliding Window Maximum (#239)LeetCodeHard
Permutation in String (#567)LeetCodeMedium

Kadane's Algorithm

Find the maximum sum contiguous subarray in O(n). The foundation of many DP problems.

ProblemPlatformDifficulty
Maximum Subarray (#53)LeetCodeMedium
Maximum Product Subarray (#152)LeetCodeMedium
Maximum Sum Circular Subarray (#918)LeetCodeMedium
Best Time to Buy and Sell Stock (#121)LeetCodeEasy

Merge Intervals

Sort intervals by start time, then merge overlapping ones. Foundation for all interval problems.

ProblemPlatformDifficulty
Merge Intervals (#56)LeetCodeMedium
Insert Interval (#57)LeetCodeMedium
Non-overlapping Intervals (#435)LeetCodeMedium
Meeting Rooms II (#253)LeetCodeMedium

Prefix Sums

Precompute cumulative sums to answer range sum queries in O(1). Combine with hashmap for subarray sum problems.

ProblemPlatformDifficulty
Range Sum Query - Immutable (#303)LeetCodeEasy
Subarray Sum Equals K (#560)LeetCodeMedium
Product of Array Except Self (#238)LeetCodeMedium
Contiguous Array (#525)LeetCodeMedium

Top K Elements

Use heaps (priority queues) or quickselect to find the K largest/smallest/most frequent elements.

ProblemPlatformDifficulty
Kth Largest Element in an Array (#215)LeetCodeMedium
Top K Frequent Elements (#347)LeetCodeMedium
K Closest Points to Origin (#973)LeetCodeMedium
Find Median from Data Stream (#295)LeetCodeHard
Merge K Sorted Lists (#23)LeetCodeHard

Monotonic Stack / Queue

Maintain a stack/deque in sorted order to find next greater/smaller elements or sliding window extremes in O(n).

ProblemPlatformDifficulty
Daily Temperatures (#739)LeetCodeMedium
Next Greater Element I (#496)LeetCodeEasy
Largest Rectangle in Histogram (#84)LeetCodeHard
Sliding Window Maximum (#239)LeetCodeHard

BFS (Breadth-First Search)

Level-by-level exploration. Guarantees shortest path in unweighted graphs. Use a queue.

ProblemPlatformDifficulty
Number of Islands (#200)LeetCodeMedium
Binary Tree Level Order Traversal (#102)LeetCodeMedium
Rotting Oranges (#994)LeetCodeMedium
Word Ladder (#127)LeetCodeHard
Open the Lock (#752)LeetCodeMedium

Multi-Source BFS

Start BFS from multiple sources simultaneously. Used for "spread" problems (fire, infection, distance from nearest).

ProblemPlatformDifficulty
Rotting Oranges (#994)LeetCodeMedium
01 Matrix (#542)LeetCodeMedium
Walls and Gates (#286)LeetCodeMedium
Shortest Bridge (#934)LeetCodeMedium

Topological Sort

Order vertices of a DAG so every edge goes from earlier to later. Kahn's (BFS with indegree) or DFS post-order.

ProblemPlatformDifficulty
Course Schedule (#207)LeetCodeMedium
Course Schedule II (#210)LeetCodeMedium
Alien Dictionary (#269)LeetCodeHard
Parallel Courses (#1136)LeetCodeMedium

Dijkstra's Algorithm

Shortest path in weighted graphs with non-negative edges. Uses a min-heap (priority queue).

ProblemPlatformDifficulty
Network Delay Time (#743)LeetCodeMedium
Cheapest Flights Within K Stops (#787)LeetCodeMedium
Path with Maximum Probability (#1514)LeetCodeMedium
Swim in Rising Water (#778)LeetCodeHard

DFS (Depth-First Search)

Go as deep as possible before backtracking. Recursion or explicit stack. Used for trees, graphs, connectivity.

ProblemPlatformDifficulty
Number of Islands (#200)LeetCodeMedium
Max Area of Island (#695)LeetCodeMedium
Clone Graph (#133)LeetCodeMedium
Pacific Atlantic Water Flow (#417)LeetCodeMedium
Number of Connected Components (#323)LeetCodeMedium

Bipartite Graph

2-color the graph using BFS/DFS. If any edge connects same-color nodes, it's not bipartite.

ProblemPlatformDifficulty
Is Graph Bipartite? (#785)LeetCodeMedium
Possible Bipartition (#886)LeetCodeMedium
Codeforces: Bipartiteness (862B)Codeforces1400

Backtracking

Choose-explore-unchoose. Generate all permutations, combinations, subsets, or valid configurations.

ProblemPlatformDifficulty
Subsets (#78)LeetCodeMedium
Permutations (#46)LeetCodeMedium
Combination Sum (#39)LeetCodeMedium
Word Search (#79)LeetCodeMedium
N-Queens (#51)LeetCodeHard

Sieve of Eratosthenes

Find all primes up to N in O(N log log N). Essential for number theory problems in CP.

ProblemPlatformDifficulty
Count Primes (#204)LeetCodeMedium
Four Divisors (#1390)LeetCodeMedium
Closest Prime Numbers in Range (#2523)LeetCodeMedium
CSES: Counting DivisorsCSESMedium

Line Sweep

Convert intervals to +1/-1 events, sort, and sweep to find peak overlaps, skylines, or coverage.

ProblemPlatformDifficulty
Meeting Rooms II (#253)LeetCodeMedium
The Skyline Problem (#218)LeetCodeHard
My Calendar I (#729)LeetCodeMedium
My Calendar III (#732)LeetCodeHard

Dynamic Programming (General)

Break problems into overlapping subproblems. Memoize (top-down) or tabulate (bottom-up). The most important pattern in CP.

ProblemPlatformDifficulty
Climbing Stairs (#70)LeetCodeEasy
House Robber (#198)LeetCodeMedium
Coin Change (#322)LeetCodeMedium
Unique Paths (#62)LeetCodeMedium
CSES: Dice CombinationsCSESEasy

Fibonacci DP

Problems where dp[i] depends on dp[i-1] and dp[i-2] (or similar small lookback). Often optimizable to O(1) space.

ProblemPlatformDifficulty
Fibonacci Number (#509)LeetCodeEasy
Climbing Stairs (#70)LeetCodeEasy
House Robber (#198)LeetCodeMedium
Decode Ways (#91)LeetCodeMedium

Take It or Leave It (Knapsack DP)

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.

ProblemPlatformDifficulty
Partition Equal Subset Sum (#416)LeetCodeMedium
Target Sum (#494)LeetCodeMedium
Last Stone Weight II (#1049)LeetCodeMedium
Ones and Zeroes (#474)LeetCodeMedium
CSES: Book ShopCSESMedium

Longest Increasing Subsequence DP

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].

ProblemPlatformDifficulty
Longest Increasing Subsequence (#300)LeetCodeMedium
Number of Longest Increasing Subsequence (#673)LeetCodeMedium
Russian Doll Envelopes (#354)LeetCodeHard
Longest String Chain (#1048)LeetCodeMedium

Regular Tier Graduation Checklist

Before moving to Magical, you should be able to:

  • Identify which of these 22 patterns applies to a new problem within 2-3 minutes
  • Code any of these patterns from scratch in under 10 minutes
  • Solve LeetCode Mediums using these patterns in under 25 minutes
  • Consistently solve 2-3 problems in LeetCode Weekly Contests
  • Have solved at least 150-200 problems total

3. Magical Algorithms Intermediate

These algorithms appear in harder contest problems and are the bridge between "solid" and "strong" competitive programmers.

Floyd Warshall

All-pairs shortest path in O(V^3). Simple triple nested loop. Works with negative edges (no negative cycles).

ProblemPlatformDifficulty
Find the City With the Smallest Number of Neighbors (#1334)LeetCodeMedium
Shortest Path Visiting All Nodes (#847)LeetCodeHard
CSES: Shortest Routes IICSESMedium
Codeforces: Greg and Graph (295B)Codeforces1700

Bitmask DP

Use a bitmask to represent subsets. dp[mask] = answer for the subset represented by mask. O(2^n * n).

ProblemPlatformDifficulty
Partition to K Equal Sum Subsets (#698)LeetCodeMedium
Shortest Path Visiting All Nodes (#847)LeetCodeHard
Maximum Students Taking Exam (#1349)LeetCodeHard
CSES: Hamiltonian FlightsCSESHard
Codeforces: Matching Burnside (to practice bitmask enumeration)Codeforces1800

Bellman Ford

Single-source shortest path that handles negative weights. Relax all edges V-1 times. Detects negative cycles.

ProblemPlatformDifficulty
Cheapest Flights Within K Stops (#787)LeetCodeMedium
Network Delay Time (#743)LeetCodeMedium
CSES: Cycle FindingCSESMedium
CSES: High Score (negative cycle detection)CSESHard

NlogN LIS (Patience Sorting)

Optimize LIS from O(n^2) to O(n log n) using binary search on a "tails" array. Essential for large inputs in CP.

ProblemPlatformDifficulty
Longest Increasing Subsequence (#300)LeetCodeMedium
Russian Doll Envelopes (#354)LeetCodeHard
Maximum Length of Pair Chain (#646)LeetCodeMedium
CSES: TowersCSESMedium

Magical Tier Graduation Checklist

  • Comfortable implementing Floyd Warshall, Bellman Ford, and Bitmask DP from scratch
  • Can solve LeetCode Hards using these patterns
  • Codeforces rating around 1400-1800
  • Consistently solve 3-4 problems in LeetCode Weekly Contests
  • Have solved at least 300-400 problems total

4. Rare Algorithms Advanced

These show up in Div 1 problems and harder LeetCode Hards. Learning these separates you from most competitive programmers.

Digit DP

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.

ProblemPlatformDifficulty
Numbers At Most N Given Digit Set (#902)LeetCodeHard
Count of Integers (#2719)LeetCodeHard
Non-negative Integers without Consecutive Ones (#600)LeetCodeHard
CSES: Counting NumbersCSESHard
Codeforces: Magic Numbers (628D)Codeforces2200

Fenwick Tree (Binary Indexed Tree)

Supports point updates and prefix sum queries in O(log n). Simpler to implement than segment tree. Uses bit manipulation to navigate the tree.

ProblemPlatformDifficulty
Range Sum Query - Mutable (#307)LeetCodeMedium
Count of Smaller Numbers After Self (#315)LeetCodeHard
Reverse Pairs (#493)LeetCodeHard
CSES: Dynamic Range Sum QueriesCSESMedium
CSES: Nested Ranges CountCSESHard

Eulerian Paths

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).

ProblemPlatformDifficulty
Reconstruct Itinerary (#332)LeetCodeHard
Valid Arrangement of Pairs (#2097)LeetCodeHard
Cracking the Safe (#753)LeetCodeHard
CSES: Mail DeliveryCSESHard

Rare Tier Graduation Checklist

  • Can implement Fenwick Tree and Digit DP from memory
  • Know when to use Fenwick vs Segment Tree
  • Codeforces rating around 1800-2100
  • Can solve most LeetCode Hards within 45 minutes

5. Epic Algorithms Expert

Expert-level data structures and string algorithms. These unlock the hardest contest problems.

Knuth-Morris-Pratt (KMP)

Find pattern in text in O(n + m) using a failure/prefix function. No backtracking in the text. Essential for string matching in CP.

ProblemPlatformDifficulty
Find the Index of the First Occurrence (#28)LeetCodeEasy
Repeated Substring Pattern (#459)LeetCodeEasy
Shortest Palindrome (#214)LeetCodeHard
CSES: String MatchingCSESMedium
Codeforces: Password (126B)Codeforces1700

Segment Tree

Range queries and range/point updates in O(log n). Supports sum, min, max, GCD, and more. Lazy propagation for range updates.

ProblemPlatformDifficulty
Range Sum Query - Mutable (#307)LeetCodeMedium
Count of Range Sum (#327)LeetCodeHard
Falling Squares (#699)LeetCodeHard
CSES: Dynamic Range Minimum QueriesCSESMedium
CSES: Range Update QueriesCSESMedium
Codeforces: Sereja and Brackets (380C)Codeforces2000

Rolling Hash (Rabin-Karp)

Hash substrings in O(1) after O(n) preprocessing. Compare substrings without character-by-character comparison. Great for pattern matching and palindrome detection.

ProblemPlatformDifficulty
Longest Duplicate Substring (#1044)LeetCodeHard
Distinct Echo Substrings (#1316)LeetCodeHard
Longest Happy Prefix (#1392)LeetCodeHard
CSES: String HashingCSESMedium

Epic Tier Graduation Checklist

  • Can implement Segment Tree with lazy propagation from scratch
  • Comfortable with KMP prefix function and its applications
  • Can use rolling hash to solve substring problems efficiently
  • Codeforces rating around 2100-2400
  • Regularly solve 4+ problems in Codeforces Div 2 contests

6. Legendary Algorithms God Tier

The final boss. FFT is rarely needed but when it is, nothing else will work. This is what separates the top 1%.

Fast Fourier Transform (FFT)

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.

ProblemPlatformDifficulty
Multiply Strings (#43) (motivational -- FFT overkill here)LeetCodeMedium
CSES: Polynomial MultiplicationCSESHard
Codeforces: Yet Another Counting Problem (practice convolution)Codeforces2300+
AtCoder: Convolution (practice problem from AtCoder Library)AtCoderHard
Reality Check

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.

7. Platforms & Resources

Where to Practice

PlatformBest ForHow 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.

Books & References

Learning C++ for Competitive Programming

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:

Recommended Progression by Platform

Path

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

Competitions & Tournaments (Win Prizes)

Competitive programming isn't just for practice -- there are real competitions with real prizes. Here's where you can compete and potentially earn money.

Regular Contests (Weekly/Biweekly)

ContestFrequencyPrizesNotes
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.

Major Competitions with Cash Prizes

CompetitionWhenPrize PoolRequirements
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.
Strategy for Winning

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.

8. Weekly Training Schedule

Consistency beats intensity. Here's a sustainable schedule for getting cracked at CP.

DayFocusTimeActivity
MondayNew Pattern1.5-2 hrsLearn one new algorithm/pattern. Read theory, understand the template, code it from scratch.
TuesdayPractice1.5-2 hrsSolve 3-4 problems using Monday's pattern. Start easy, increase difficulty.
WednesdayMixed Practice1.5-2 hrsSolve 3-4 random problems (no topic filter). Practice pattern recognition.
ThursdayHard Problems1.5-2 hrsAttempt 1-2 hard problems. Spend 30 min each, then read editorials if stuck.
FridayReview1 hrRe-solve problems you got wrong this week without looking at solutions.
SaturdayContest2-2.5 hrsLeetCode Weekly Contest OR Codeforces Round (virtual or live).
SundayUpsolve1.5 hrsSolve the contest problems you couldn't solve. Read editorials for every unsolved problem.
Total: ~11-13 hours/week. Adjust based on your schedule. The minimum effective dose is 1 hour/day, 5 days/week. Less than that and progress stalls.

The 30-Minute Rule

For every problem:

Common Mistake

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.

When to Move to the Next Tier

Final Advice

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.