DSA Notes
Master competitive programming contest strategies — pre-contest preparation, during-contest time management, the scanning strategy, when to skip problems, stress testing techniques, hacking, debugging under pressure, post-contest upsolving, and mental management during competition.
Introduction
Technical knowledge is necessary but not sufficient for competitive programming success. Two programmers with identical algorithmic knowledge can have dramatically different results in the same contest based on strategy, mental management, and experience.
This lesson teaches the non-technical skills that can move you 200-500 rating points without learning a single new algorithm.
During the Contest — The First 10 Minutes
The scanning strategy is critical. Most beginners make the mistake of reading only the first problem and immediately coding. This is wrong.
The Right Approach
Why this matters: Sometimes Problem C is actually easier than B for your skill set, or Problem D has a clean solution you recognize immediately. Scanning everything first lets you prioritize correctly.
Time Management During Contest
The 80/20 Rule of Contests
80% of your rating points come from problems you can solve comfortably. Spending 90 minutes on an unsolvable problem while missing problems you could have solved is the #1 mistake beginners make.
The 15-Minute Abandon Rule
Time Budget per Problem (Div 2)
| Problem | Target Time | Max Time Before Skip |
|---|---|---|
| A | 5-10 min | 15 min |
| B | 10-20 min | 30 min |
| C | 20-40 min | 50 min |
| D | 35-60 min | 70 min |
| E | 45-90 min | Skip if C/D unsolved |
Reading Problems Correctly
What to Look for Immediately
| n ≤ 10^5 | algorithm must be O(n log n) or O(n) |
| n ≤ 10^3 | O(n²) works |
| n ≤ 20 | O(2^n) or O(n!) possible |
The Restatement Method
After reading, close your eyes and restate the problem in your own words. If you can't, read again. You'd be surprised how many wrong submissions come from misunderstanding the problem.
Coding Strategy
Write Pseudocode First (for harder problems)
For problems C and harder
1. Write algorithm in comments (2-3 minutes)
2. Verify the algorithm on the examples manually
3. Only then write actual code
Example
// Sort array
// For each element, binary search for complement
// If found, return pair
Test Before Submitting
Integer Overflow — The Silent Killer
// Problem: n ≤ 10^5, values ≤ 10^5
// Trap: sum can be n × max_val = 10^5 × 10^5 = 10^10 > INT_MAX (2.1 × 10^9)
int sum = 0; // WRONG: Will overflow
for (int x : arr) sum += x;
long long sum = 0; // CORRECT: long long holds up to ~9.2 × 10^18
for (int x : arr) sum += x;
// Rule: Whenever multiplying/summing large values, use long longStress Testing — Verifying Your Solution
Stress testing is running your solution against a brute force on random small inputs to find bugs.
This catches bugs that examples don't reveal. Many TLE or WA solutions have passed a 10-minute stress test to reveal the exact failing input.
Hacking (Codeforces Specific)
After the coding phase, Codeforces allows "hacking" — submitting test cases to break other participants' solutions. This is optional but can earn points.
How to hack effectively:
Warning: A failed hack (your input doesn't actually break their code) costs you 50 rating points. Only hack when very confident.
Post-Contest — The Learning Phase
The contest is over, but the real learning begins now.
Immediate Post-Contest (Same Day)
The Upsolving Process
What to Track
Mental Management
Dealing with TLE (Time Limit Exceeded)
Dealing with WA (Wrong Answer)
| Wrong reaction | "My code looks right, maybe the judge is wrong" |
| 2. Check edge cases | n=1, all zeros, negative values, overflow |
| 3. Check output format | trailing spaces, newlines, case sensitivity |
When to Give Up on a Problem
Give up and move to next problem when
→ You've been stuck for 20+ minutes with no progress
→ You've tried 3 different approaches and all fail
→ You have other unsolved problems you might solve
Give up and stop contest attempts when
→ Your WA count on a problem is 5+
(Each wrong submission is -50 points, you're digging deeper)
Summary — The Contest Checklist
Pre-Contest
- [ ] Template ready and tested
- [ ] IDE/compiler working
- [ ] Distractions minimized
First 10 Minutes
- [ ] Read ALL problems quickly
- [ ] Estimate difficulty of each
- [ ] Decide solving order
For Each Problem
- [ ] Understand examples completely
- [ ] Check constraints → determine required complexity
- [ ] State algorithm in pseudocode before coding
- [ ] Test on examples before submitting
- [ ] Check for overflow with large inputs
Post-Contest
- [ ] Upsolve every problem you couldn't solve
- [ ] Read all editorials
- [ ] Note down key insights
Competitive programming rewards preparation, strategy, and consistency. The programmer with great strategy and average algorithms often outperforms the programmer with brilliant algorithms and poor strategy. Master both and you will climb rapidly.
*Competitive Programming section complete.*
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Contest Strategies — How to Perform Your Best in Competitive Programming Contests.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Data Structures & Algorithms topic.
Search Terms
data-structures-algorithms, data structures & algorithms, data, structures, algorithms, competitive, programming, contest
Related Data Structures & Algorithms Topics