Codeforces Problem Types
Problems LeetCode Doesn’t Prepare You For
LeetCode focuses on specific data structures and algorithms. Codeforces has its own flavor of problems that can feel alien at first.Type 1: Construction Problems
What It Is
Given constraints, construct an array/string/sequence that satisfies them—or report impossible.Example Pattern
“Construct an array of n integers where sum is S and maximum element is M, or print -1 if impossible.”
How to Approach
1
Find Necessary Conditions
What must be true for a solution to exist?
2
Check Impossibility
If conditions fail, print -1 or NO.
3
Construct Greedily
Build the simplest valid answer.
Example
Problem: Construct an array of n positive integers with sum S.Classic CF Problems
Type 2: Binary String Problems
What It Is
Operations on binary strings (0s and 1s) with specific rules.Common Operations
- Flip a character
- Swap adjacent characters
- Remove/add characters
- Make all characters same
Key Observations
Example
Problem: Minimum operations to make binary string alternating.Classic CF Problems
Type 3: MEX Problems
What It Is
MEX = Minimum EXcludant = Smallest non-negative integer NOT in a set.Computing MEX
Classic CF Problems
Type 4: Permutation Problems
What It Is
An array of n elements containing each number from 1 to n exactly once.Key Properties
Classic CF Problems
Type 5: Game Theory / Turn-Based
What It Is
Alice and Bob take turns. Who wins with optimal play?Key Patterns
Classic Insights
- Nim: XOR of pile sizes
- Sprague-Grundy: Every game position has a Grundy number
- Parity: Count total moves
- Symmetry: Copy opponent’s moves
Classic CF Problems
Type 6: Counting / Combinatorics
What It Is
Count arrangements, combinations, or ways to achieve something, often modulo 10^9+7.Key Formulas
Classic CF Problems
Type 7: Interval / Range Problems
What It Is
Problems involving segments [l, r] on a number line.Key Techniques
Classic CF Problems
Type 8: Interactive Problems
What It Is
Your program asks queries, the judge responds, and you find the answer within a query limit.Key Rules
Common Patterns
- Binary Search: Query middle, narrow range
- Comparison Queries: “Is A > B?”
- Subset Queries: “What is f(subset)?”
Example: Binary Search Interactive
Classic CF Problems
Type 9: Ad-Hoc / Observation
What It Is
Problems that require a clever observation rather than standard algorithms.How to Approach
1
Try Small Cases
Work through n=1, 2, 3, 4 by hand.
2
Look for Patterns
Does a formula emerge? Parity? Special structure?
3
Simplify the Problem
What’s the simplest version of this problem?
4
Think About Necessary Conditions
What must be true for a solution to exist?
Red Flags for Ad-Hoc
- Problem seems “too simple” for its rating
- Constraints are unusual (very small or very specific)
- Problem involves specific numerical properties
- Standard algorithms don’t obviously apply
Classic CF Problems
Quick Recognition Guide
| See This | Think This |
|---|---|
| ”Construct array…” | Construction problem |
| Binary string, 0s and 1s | Binary string manipulation |
| MEX, mex, minimum excludant | MEX techniques |
| ”Permutation of 1 to n” | Permutation properties |
| ”Alice and Bob” | Game theory |
| ”Count the number” | Combinatorics |
| ”In range [l, r]“ | Interval techniques |
| ”Query” + output flush | Interactive |
| Nothing standard applies | Ad-hoc observation |
Practice by Type
Solve 5-10 problems of each type to build recognition:- Construction: Filter by “constructive algorithms” tag
- Binary String: Search for binary string in recent problems
- MEX: Filter by “games” + MEX keyword
- Permutation: Filter by “math” + permutation keyword
- Game Theory: Filter by “games” tag
- Counting: Filter by “combinatorics” tag
- Interactive: Filter by “interactive” tag