DSA Notes
Winning strategies for programming contests: time management, problem selection, debugging under pressure, and minimizing penalty time.
The Mental Game
A programming contest is not just about algorithms — it is about performing under pressure. I have seen brilliant programmers bomb contests because they panicked on problem B while problem D was easier. Contest strategy is the multiplier on your skill.
The fundamental truth: your rank depends more on what you choose to attempt than on raw algorithmic ability. A well-strategized contestant who solves A, B, D in 80 minutes will outrank someone who spends 120 minutes solving A, B, C.
Rule 1: Read All Problems First (5-10 Minutes)
Before writing a single line of code, spend 5-10 minutes scanning ALL problem statements. Read the title, the problem statement's first paragraph, the constraints, and the examples. You are building a mental map:
- Which problems are implementation-heavy but conceptually simple?
- Which problems have small constraints (N ≤ 20 → bitmask, N ≤ 8 → brute force)?
- Which problems look like standard techniques you know?
This prevents the classic mistake: grinding problem C for 60 minutes while problem E was a straightforward BFS that you could solve in 10 minutes.
Rule 2: Start with the Easiest, Not Problem A
Problems are generally ordered by difficulty, but not always. Sometimes B is easier than A, or D is easier than C for your specific skill set. After your initial scan:
- Solve the clearly easiest problem first (builds confidence, gets points on board)
- Then tackle problems in YOUR order of confidence, not A-B-C-D order
- If equally confident about two problems, pick the one with more solves (check the scoreboard)
Rule 3: The 15-Minute Rule
If you have been stuck on a problem for 15 minutes without making progress, STOP. Either:
- Switch to another problem and come back later with fresh eyes
- Simplify your approach — maybe you are overcomplicating it
- Re-read the problem statement — you might have missed a constraint
Do NOT spend 45 minutes debugging one approach when you could solve another problem cleanly in 20 minutes. Time spent is a sunk cost.
Time Management Framework
For a 2-hour, 6-problem Codeforces Div. 2 contest:
| Time | Target Action |
|---|---|
| 0:00-0:10 | Scan all problems, identify easy ones |
| 0:10-0:25 | Solve Problem A (should take <15 min) |
| 0:25-0:50 | Solve Problem B |
| 0:50-1:20 | Attempt Problem C or D (whichever looks more approachable) |
| 1:20-1:50 | Attempt the other of C/D |
| 1:50-2:00 | Recheck solutions, handle edge cases, try E if time permits |
Adjust based on your level. Beginners might spend 30 minutes on A and that is fine. The key is having a time plan rather than drifting.
Debugging Under Pressure
Bugs during contests feel catastrophic because of the ticking clock. Here is a systematic approach:
Step 1: Test with the Given Examples
If your solution fails the given examples, the bug is usually obvious. Walk through your code manually with the example input.
Step 2: Test Edge Cases
Generate these mentally or on paper:
- Empty input / minimum constraints (n=1)
- Maximum constraints (will it TLE?)
- All same elements
- Already sorted / reverse sorted
- Negative numbers (if allowed)
Step 3: Print Debugging
Add strategic print statements at decision points:
// Before submission, add prints to trace logic
cerr << "i=" << i << " val=" << val << " sum=" << sum << endl;Use cerr (not cout) so you do not accidentally leave debug output in your submission.
Step 4: Stress Testing
If you have a brute force solution and an optimized one, compare their outputs on random small inputs:
while (true) {
auto input = generateRandom(n=10);
auto brute = bruteForce(input);
auto fast = optimized(input);
if (brute != fast) {
printInput(input);
cout << "BRUTE: " << brute << " FAST: " << fast << endl;
break;
}
}Penalty Time and Scoring
ICPC-Style Scoring
- Sort by number of problems solved
- Ties broken by total penalty time
- Penalty = time of accepted submission + 20 minutes per wrong submission
- Implication: Do NOT submit until you are fairly confident. One wrong submission = 20 minutes penalty.
Codeforces Scoring
- Each problem has max points that decrease over time
- Wrong submissions add no time penalty but reduce score slightly
- Implication: Submit early even if slightly uncertain. The time decay of points matters more than the -50 per WA.
LeetCode Contest Scoring
- Points per problem (Easy=3, Medium=5, Hard=7 roughly)
- 5-minute penalty per wrong submission
- Implication: Similar to Codeforces — speed matters, but verify examples before submitting.
Pre-Contest Preparation
Day Before
- Get good sleep (seriously — cognitive function drops 30% when tired)
- Review your template and library code
- Do a light warmup (1-2 Easy problems)
- Check the contest time and set an alarm
10 Minutes Before
- Open your IDE, compile your template, verify it runs
- Have a glass of water nearby
- Close all distracting tabs (social media, chat)
- Take a few deep breaths — calm focus beats frantic energy
Common Tactical Mistakes
- Not reading constraints: Wastes 30 minutes implementing O(n log n) when O(n²) suffices for n ≤ 1000
- Overthinking Problem A: If A looks too simple, it probably IS that simple. Trust it.
- Refusing to abandon an approach: If you have been coding for 20 minutes and it keeps getting more complicated, your approach is likely wrong. Start fresh.
- Not using prewritten code: Have standard implementations ready (DSU, segment tree, Dijkstra). Typing them from scratch wastes 10+ minutes.
- Submitting without testing: Always test against ALL provided examples before submitting.
- Tilting after a WA: Stay calm. Analyze why it failed. Do not randomly change code hoping it works.
Post-Contest: The Most Important Part
Upsolving — solving the problems you could not get during the contest — is where 80% of learning happens. After every contest:
- Read the editorial for every unsolved problem
- Implement the solution yourself (do not copy)
- If the technique was new, add it to your notebook
- Ask yourself: "What should I have recognized during the contest?"
Track your performance over time. Note which categories you consistently struggle with. Direct your practice toward those weaknesses.
Team Contest Strategies (ICPC-Style)
If competing in a team of 3 with one computer:
- First 10 minutes: All three read all problems. Discuss and assign.
- Assign by strength: Give DP problems to the DP specialist, graphs to the graph person.
- Parallelize thinking: While one person codes, others solve on paper.
- Rotate the keyboard: No one should code for more than 30 minutes straight.
- Communication is key: Say "I think D is a segment tree problem" out loud — your teammate might disagree and save you time.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Contest Strategies for Competitive Programming.
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