Skip to content
We areTOP 1%
DSA · 9 patterns · 114 questions

Competitive Programmer DSA

For students aiming at Codeforces Expert and above, or at the hardest online assessments. Covers number theory, combinatorics, constructive thinking, range-query data structures, advanced DP, graph algorithms beyond traversal, string matching and combinatorial games.
Competitive Programmer progress0%
1st Visit
0/114
2nd Visit
0/114
Revise
0/114

Number Theory

0/14

Number theory problems revolve around divisibility, primes, gcd and lcm, and modular arithmetic. The core tools are the Euclidean algorithm, a sieve of Eratosthenes or…

Pattern guide
Number Theory questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Orac and LCMCodeforcesMedium 1600Solve Orac and LCM on Codeforces (opens in a new tab)
2Ugly Number IIILeetCodeMedium Solve Ugly Number III on LeetCode (opens in a new tab)
3Same GCDsCodeforcesHard 1800Solve Same GCDs on Codeforces (opens in a new tab)
4Check If It Is a Good ArrayLeetCodeHard Solve Check If It Is a Good Array on LeetCode (opens in a new tab)
5K-goodCodeforcesHard 1900Solve K-good on Codeforces (opens in a new tab)
6Strange BeautyCodeforcesHard 1900Solve Strange Beauty on Codeforces (opens in a new tab)
7Number of Different Subsequences GCDsLeetCodeHard Solve Number of Different Subsequences GCDs on LeetCode (opens in a new tab)
8Count Array Pairs Divisible by KLeetCodeHard Solve Count Array Pairs Divisible by K on LeetCode (opens in a new tab)
9The Football SeasonCodeforcesHard 2000Solve The Football Season on Codeforces (opens in a new tab)
10CGCDSSQCodeforcesHard 2000Solve CGCDSSQ on Codeforces (opens in a new tab)
11Two DivisorsCodeforcesHard 2000Solve Two Divisors on Codeforces (opens in a new tab)
12Maximum ValueCodeforcesHard 2100Solve Maximum Value on Codeforces (opens in a new tab)
13The Number of PairsCodeforcesHard 2100Solve The Number of Pairs on Codeforces (opens in a new tab)
14Count PairsCodeforcesHard 2300Solve Count Pairs on Codeforces (opens in a new tab)

Combinatorics & Modular Arithmetic

0/12

Counting problems ask for the number of arrangements, sequences or selections, usually modulo a prime such as 1e9+7 or 998244353. Precompute factorials and inverse…

Pattern guide
Combinatorics & Modular Arithmetic questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Two ArraysCodeforcesMedium 1600Solve Two Arrays on Codeforces (opens in a new tab)
2Count All Valid Pickup and Delivery OptionsLeetCodeHard Solve Count All Valid Pickup and Delivery Options on LeetCode (opens in a new tab)
3Count the ArraysCodeforcesMedium 1700Solve Count the Arrays on Codeforces (opens in a new tab)
4Count AnagramsLeetCodeHard Solve Count Anagrams on LeetCode (opens in a new tab)
5AquaMoon and ChessCodeforcesHard 1900Solve AquaMoon and Chess on Codeforces (opens in a new tab)
6Divide and SumCodeforcesHard 1900Solve Divide and Sum on Codeforces (opens in a new tab)
7Number of Ways to Reorder Array to Get Same BSTLeetCodeHard Solve Number of Ways to Reorder Array to Get Same BST on LeetCode (opens in a new tab)
8Modular StabilityCodeforcesHard 2000Solve Modular Stability on Codeforces (opens in a new tab)
9Coprime SubsequencesCodeforcesHard 2000Solve Coprime Subsequences on Codeforces (opens in a new tab)
10Count the Number of Ideal ArraysLeetCodeHard Solve Count the Number of Ideal Arrays on LeetCode (opens in a new tab)
11Gerald and Giant ChessCodeforcesHard 2200Solve Gerald and Giant Chess on Codeforces (opens in a new tab)
12Devu and FlowersCodeforcesHard 2300Solve Devu and Flowers on Codeforces (opens in a new tab)

Constructive Algorithms

0/15

Constructive problems ask you to build any valid object, such as a permutation, an array, a string or a sequence of operations, rather than compute a single number…

Pattern guide
Constructive Algorithms questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Beautiful Arrangement IILeetCodeMedium Solve Beautiful Arrangement II on LeetCode (opens in a new tab)
2Special PermutationCodeforcesMedium 1600Solve Special Permutation on Codeforces (opens in a new tab)
3Ehab and Prefix MEXsCodeforcesMedium 1600Solve Ehab and Prefix MEXs on Codeforces (opens in a new tab)
4Prefix Flip (Hard Version)CodeforcesMedium 1700Solve Prefix Flip (Hard Version) on Codeforces (opens in a new tab)
5Construct Target Array With Multiple SumsLeetCodeHard Solve Construct Target Array With Multiple Sums on LeetCode (opens in a new tab)
6Find the Closest PalindromeLeetCodeHard Solve Find the Closest Palindrome on LeetCode (opens in a new tab)
7A/B MatrixCodeforcesHard 1900Solve A/B Matrix on Codeforces (opens in a new tab)
8Phoenix and ScienceCodeforcesHard 1900Solve Phoenix and Science on Codeforces (opens in a new tab)
9Replace by MEXCodeforcesHard 1900Solve Replace by MEX on Codeforces (opens in a new tab)
10Engineer ArtemCodeforcesHard 2000Solve Engineer Artem on Codeforces (opens in a new tab)
11Orac and MediansCodeforcesHard 2000Solve Orac and Medians on Codeforces (opens in a new tab)
12Make Them EqualCodeforcesHard 2000Solve Make Them Equal on Codeforces (opens in a new tab)
13Transform to ChessboardLeetCodeHard Solve Transform to Chessboard on LeetCode (opens in a new tab)
14Errich-Tac-Toe (Easy Version)CodeforcesHard 2100Solve Errich-Tac-Toe (Easy Version) on Codeforces (opens in a new tab)
15Multiples and Power DifferencesCodeforcesHard 2200Solve Multiples and Power Differences on Codeforces (opens in a new tab)

Segment Tree & Fenwick Tree

0/13

Range query structures answer questions about subarrays while the array keeps changing. A Fenwick tree, or binary indexed tree, supports point updates and prefix sums…

Pattern guide
Segment Tree & Fenwick Tree questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Range Sum Query - MutableLeetCodeMedium Solve Range Sum Query - Mutable on LeetCode (opens in a new tab)
2Xenia and Bit OperationsCodeforcesMedium 1700Solve Xenia and Bit Operations on Codeforces (opens in a new tab)
3Count of Smaller Numbers After SelfLeetCodeHard Solve Count of Smaller Numbers After Self on LeetCode (opens in a new tab)
4Pashmak and Parmida's problemCodeforcesHard 1800Solve Pashmak and Parmida's problem on Codeforces (opens in a new tab)
5Count of Range SumLeetCodeHard Solve Count of Range Sum on LeetCode (opens in a new tab)
6Enemy is weakCodeforcesHard 1900Solve Enemy is weak on Codeforces (opens in a new tab)
7MultisetCodeforcesHard 1900Solve Multiset on Codeforces (opens in a new tab)
8Longest Increasing Subsequence IILeetCodeHard Solve Longest Increasing Subsequence II on LeetCode (opens in a new tab)
9Sereja and BracketsCodeforcesHard 2000Solve Sereja and Brackets on Codeforces (opens in a new tab)
10XOR on SegmentCodeforcesHard 2000Solve XOR on Segment on Codeforces (opens in a new tab)
11SUM and REPLACECodeforcesHard 2000Solve SUM and REPLACE on Codeforces (opens in a new tab)
12Ant colonyCodeforcesHard 2100Solve Ant colony on Codeforces (opens in a new tab)
13A Simple TaskCodeforcesHard 2300Solve A Simple Task on Codeforces (opens in a new tab)

Advanced DP (Bitmask, Digit, Interval)

0/15

Some DP states do not fit a simple index. Bitmask DP encodes a subset of up to about 20 items in an integer, as in dp[mask][last] for ordering or assignment problems…

Pattern guide
Advanced DP (Bitmask, Digit, Interval) questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Kefa and DishesCodeforcesHard 1800Solve Kefa and Dishes on Codeforces (opens in a new tab)
2Minimum Cost to Cut a StickLeetCodeHard Solve Minimum Cost to Cut a Stick on LeetCode (opens in a new tab)
3Shortest Path Visiting All NodesLeetCodeHard Solve Shortest Path Visiting All Nodes on LeetCode (opens in a new tab)
4Burst BalloonsLeetCodeHard Solve Burst Balloons on LeetCode (opens in a new tab)
5ZumaCodeforcesHard 1900Solve Zuma on Codeforces (opens in a new tab)
6FishCodeforcesHard 1900Solve Fish on Codeforces (opens in a new tab)
7Classy NumbersCodeforcesHard 1900Solve Classy Numbers on Codeforces (opens in a new tab)
8Number of Digit OneLeetCodeHard Solve Number of Digit One on LeetCode (opens in a new tab)
9Find the Shortest SuperstringLeetCodeHard Solve Find the Shortest Superstring on LeetCode (opens in a new tab)
10Clear the StringCodeforcesHard 2000Solve Clear the String on Codeforces (opens in a new tab)
11Square SubsetsCodeforcesHard 2000Solve Square Subsets on Codeforces (opens in a new tab)
12Array ShrinkingCodeforcesHard 2100Solve Array Shrinking on Codeforces (opens in a new tab)
13Compatible NumbersCodeforcesHard 2200Solve Compatible Numbers on Codeforces (opens in a new tab)
14Magic NumbersCodeforcesHard 2200Solve Magic Numbers on Codeforces (opens in a new tab)
15Segment SumCodeforcesHard 2300Solve Segment Sum on Codeforces (opens in a new tab)

Graph Theory (MST, SCC, Bridges)

0/13

This pattern covers graph algorithms beyond traversal. A minimum spanning tree connects every vertex at the least total cost: Kruskal sorts the edges and joins…

Pattern guide
Graph Theory (MST, SCC, Bridges) questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Min Cost to Connect All PointsLeetCodeMedium Solve Min Cost to Connect All Points on LeetCode (opens in a new tab)
2CheckpostsCodeforcesMedium 1700Solve Checkposts on Codeforces (opens in a new tab)
3Critical Connections in a NetworkLeetCodeHard Solve Critical Connections in a Network on LeetCode (opens in a new tab)
40-1 MSTCodeforcesHard 1900Solve 0-1 MST on Codeforces (opens in a new tab)
5MinOr TreeCodeforcesHard 1900Solve MinOr Tree on Codeforces (opens in a new tab)
6Make It ConnectedCodeforcesHard 1900Solve Make It Connected on Codeforces (opens in a new tab)
7Find Critical and Pseudo-Critical Edges in Minimum Spanning TreeLeetCodeHard Solve Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree on LeetCode (opens in a new tab)
8Valid Arrangement of PairsLeetCodeHard Solve Valid Arrangement of Pairs on LeetCode (opens in a new tab)
9Bertown roadsCodeforcesHard 2000Solve Bertown roads on Codeforces (opens in a new tab)
10Reachability from the CapitalCodeforcesHard 2000Solve Reachability from the Capital on Codeforces (opens in a new tab)
11We Need More BossesCodeforcesHard 2100Solve We Need More Bosses on Codeforces (opens in a new tab)
12Minimum spanning tree for each edgeCodeforcesHard 2100Solve Minimum spanning tree for each edge on Codeforces (opens in a new tab)
13Edges in MSTCodeforcesHard 2300Solve Edges in MST on Codeforces (opens in a new tab)

String Algorithms (KMP, Z, Hashing)

0/11

Linear time string matching avoids the O(nm) cost of comparing a pattern at every position. The prefix function from KMP gives, for each prefix, the length of its…

Pattern guide
String Algorithms (KMP, Z, Hashing) questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Longest Happy PrefixLeetCodeHard Solve Longest Happy Prefix on LeetCode (opens in a new tab)
2PasswordCodeforcesMedium 1700Solve Password on Codeforces (opens in a new tab)
3Shortest PalindromeLeetCodeHard Solve Shortest Palindrome on LeetCode (opens in a new tab)
4Prefix-Suffix Palindrome (Hard version)CodeforcesHard 1800Solve Prefix-Suffix Palindrome (Hard version) on Codeforces (opens in a new tab)
5Sum of Scores of Built StringsLeetCodeHard Solve Sum of Scores of Built Strings on LeetCode (opens in a new tab)
6Tavas and MalekasCodeforcesHard 1900Solve Tavas and Malekas on Codeforces (opens in a new tab)
7Longest Duplicate SubstringLeetCodeHard Solve Longest Duplicate Substring on LeetCode (opens in a new tab)
8Prefixes and SuffixesCodeforcesHard 2000Solve Prefixes and Suffixes on Codeforces (opens in a new tab)
9Watto and MechanismCodeforcesHard 2000Solve Watto and Mechanism on Codeforces (opens in a new tab)
10Palindrome DegreeCodeforcesHard 2200Solve Palindrome Degree on Codeforces (opens in a new tab)
11Anthem of BerlandCodeforcesHard 2300Solve Anthem of Berland on Codeforces (opens in a new tab)

Game Theory

0/9

In an impartial game both players have the same moves, and under normal play the player who cannot move loses. Classify positions backwards: a position is winning if…

Pattern guide
Game Theory questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Stone Game IIILeetCodeHard Solve Stone Game III on LeetCode (opens in a new tab)
21-2-K GameCodeforcesMedium 1700Solve 1-2-K Game on Codeforces (opens in a new tab)
3Stoned GameCodeforcesHard 1800Solve Stoned Game on Codeforces (opens in a new tab)
4A Lot of GamesCodeforcesHard 1900Solve A Lot of Games on Codeforces (opens in a new tab)
5GameGameCodeforcesHard 1900Solve GameGame on Codeforces (opens in a new tab)
6Tree TagCodeforcesHard 1900Solve Tree Tag on Codeforces (opens in a new tab)
7Cat and MouseLeetCodeHard Solve Cat and Mouse on LeetCode (opens in a new tab)
8Not a Nim ProblemCodeforcesHard 2100Solve Not a Nim Problem on Codeforces (opens in a new tab)
9Lieges of LegendreCodeforcesHard 2200Solve Lieges of Legendre on Codeforces (opens in a new tab)

Mixed Practice

All patterns0/12

This set mixes problems from the Competitive Programmer patterns, and the pattern label is deliberately hidden. In a contest the hardest step is often deciding which…

Pattern guide
Mixed Practice questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Deleting DivisorsCodeforcesMedium 1700Solve Deleting Divisors on Codeforces (opens in a new tab)
2Enlarge GCDCodeforcesHard 1800Solve Enlarge GCD on Codeforces (opens in a new tab)
3Beautiful NumbersCodeforcesHard 1800Solve Beautiful Numbers on Codeforces (opens in a new tab)
4Kth Smallest InstructionsLeetCodeHard Solve Kth Smallest Instructions on LeetCode (opens in a new tab)
5Shichikuji and Power GridCodeforcesHard 1900Solve Shichikuji and Power Grid on Codeforces (opens in a new tab)
6Palindrome Game (hard version)CodeforcesHard 1900Solve Palindrome Game (hard version) on Codeforces (opens in a new tab)
7Reaching PointsLeetCodeHard Solve Reaching Points on LeetCode (opens in a new tab)
8Compress WordsCodeforcesHard 2000Solve Compress Words on Codeforces (opens in a new tab)
9Wish I Knew How to SortCodeforcesHard 2000Solve Wish I Knew How to Sort on Codeforces (opens in a new tab)
10Directing EdgesCodeforcesHard 2000Solve Directing Edges on Codeforces (opens in a new tab)
11Propagating treeCodeforcesHard 2000Solve Propagating tree on Codeforces (opens in a new tab)
12Circular RMQCodeforcesHard 2200Solve Circular RMQ on Codeforces (opens in a new tab)

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account