DSA Notes
A complete guide to getting started with competitive programming: what it is, why it matters, platforms to use, and a roadmap from beginner to advanced.
What is Competitive Programming?
Competitive programming (CP) is a mind sport where participants solve well-defined algorithmic problems under time constraints. You are given a problem statement, input/output specifications, and constraints — your job is to write code that produces correct output for all possible inputs within time and memory limits.
Unlike software engineering where you build systems over weeks, CP challenges you to solve self-contained puzzles in minutes. Each problem has hidden test cases, and your solution must pass all of them. There is no partial credit for code quality, documentation, or architecture — only correctness and speed matter.
Why Should You Do It?
For interviews: Companies like Google, Meta, and Amazon test algorithmic problem solving. CP builds exactly this muscle. After solving 500+ problems, a LeetCode medium feels routine.
For thinking speed: CP trains you to decompose problems rapidly. You learn to recognize patterns — "this is a shortest path problem disguised as a grid" — and apply known algorithms immediately.
For edge cases: Contest problems are designed to break naive solutions. You develop an instinct for overflow, off-by-one errors, boundary conditions, and precision issues.
For fun: There is genuine joy in cracking a problem after 45 minutes of struggle. The competitive aspect adds adrenaline — watching your rank climb during a contest is addictive.
The Problem-Solving Mindset
Competitive programming rewards a specific mental approach:
- Read carefully. The constraints (N ≤ 10^5 vs N ≤ 10^3) tell you the expected time complexity. If N ≤ 10^5, you need O(n log n) or better. If N ≤ 20, brute force or bitmask DP works.
- Think before coding. Spend 30-50% of your time on paper. Draw examples. Try small cases. Identify the pattern before writing a single line.
- Start simple. A correct brute force solution you can verify is worth more than a clever solution with a bug. Optimize only when needed.
- Know your algorithms. You cannot derive Dijkstra's algorithm during a contest. You need to have these tools pre-loaded in your brain and ready to apply.
Major Platforms
Codeforces
The largest competitive programming platform. Rated contests 2-3 times per week. Problems range from 800 (beginner) to 3500 (world-class). Excellent editorial system. Russian origin but fully English. Best for: serious competitive improvement.
LeetCode
Interview-focused platform with 2500+ problems. Weekly and biweekly contests. Problems tagged by company and topic. Best for: interview preparation and structured practice.
AtCoder
Japanese platform with exceptionally clean problem statements and strong test cases. Beginner Contest (ABC) is perfect for newcomers. Best for: learning fundamentals with well-crafted problems.
CodeChef
Indian platform with monthly Long Challenges (10 days) and shorter Cookoffs. Good for beginners due to lenient time limits. Best for: those who prefer thinking over days rather than hours.
HackerRank
Clean interface with domain-specific tracks (algorithms, data structures, math). Good for: beginners who want guided progression.
Getting Started Roadmap
Phase 1: Foundations (Weeks 1-4)
- Master a language (C++ recommended for speed, Python acceptable for clarity)
- Learn basic I/O, arrays, strings, and standard library
- Solve 50 easy problems on LeetCode or Codeforces (A-level problems)
- Topics: brute force, simple math, basic string operations, sorting
Phase 2: Core Algorithms (Weeks 5-12)
- Binary search (on arrays AND on answer)
- Two pointers and sliding window
- BFS/DFS on graphs and trees
- Dynamic programming (1D and 2D)
- Greedy algorithms
- Solve 100 medium problems across platforms
Phase 3: Intermediate (Months 3-6)
- Segment trees and Binary Indexed Trees
- Shortest path algorithms (Dijkstra, Bellman-Ford, Floyd-Warshall)
- String algorithms (KMP, Z-function, hashing)
- Number theory (modular arithmetic, Sieve of Eratosthenes)
- Participate in weekly contests consistently
Phase 4: Advanced (Months 6+)
- Advanced DP (bitmask, digit, tree DP)
- Network flow and matching
- Centroid decomposition
- Heavy-light decomposition
- Persistent data structures
- Aim for Codeforces Expert (1600+) or LeetCode top 5%
Language Choice
C++ is the dominant language in CP. Reasons:
- Fastest execution (no TLE due to language overhead)
- STL provides everything:
vector,set,map,priority_queue,__builtin_popcount - Bit manipulation is natural
- 95% of editorials and tutorials use C++
Python works for many problems but hits TLE on tight constraints. Use it if you refuse to learn C++, but know its limitations. PyPy helps.
Java is viable but verbose. Slightly slower than C++. Good if you already know it well.
Template Setup
Most competitive programmers use a template that handles common boilerplate:
Common Beginner Mistakes
- Not reading constraints: The constraint section tells you everything about expected complexity
- Integer overflow: Use
long longwhen values can exceed 2×10^9 - Not testing edge cases: Empty input, single element, all same values
- Overcomplicating: The simplest correct approach is always best
- Giving up too early: Most problems are solvable with known techniques — you just have not recognized the pattern yet
How to Improve
- Solve problems daily. Even one problem a day compounds over months.
- Read editorials after every problem you cannot solve in 45 minutes.
- Upsolve: After contests, solve the problems you missed. This is where real learning happens.
- Track patterns. Keep a notebook of problem types and their solutions.
- Virtual contests: Simulate real contest conditions for practice.
Building Your CP Toolkit
Must-Know Data Structures for CP
Before you enter any contest, these should be second nature:
- Arrays/Vectors: Dynamic arrays with push_back, sorting, binary search
- Sets and Maps: ordered (std::set/map) and unordered (hash-based)
- Priority Queue: For greedy algorithms and Dijkstra
- Stack and Queue: For BFS, DFS, parsing, monotonic problems
- Disjoint Set Union (DSU): For connectivity and Kruskal's MST
Must-Know Algorithms
- Sorting (know when built-in suffices vs custom comparator)
- Binary search (both on arrays and on answer space)
- BFS/DFS (graph traversal, connected components, cycle detection)
- Dijkstra's algorithm (shortest path with non-negative weights)
- Dynamic programming (start with 1D problems like fibonacci, then 2D)
- Greedy algorithms (activity selection, interval scheduling)
The Importance of Problem Classification
When you solve a problem, always tag it mentally: "This was a binary search on answer problem." Over time, you build a catalog of problem types. When you see a new problem in a contest, you subconsciously match it against your catalog. This pattern matching is what separates a 1200-rated coder from an 1800-rated one — both might know the same algorithms, but the higher-rated person recognizes which algorithm to apply faster.
Competitive Programming vs Software Engineering
It is worth understanding that CP skills and engineering skills overlap but are not identical. CP teaches you to:
- Write correct code quickly under pressure
- Think about algorithmic efficiency naturally
- Handle edge cases and corner cases rigorously
- Debug code mentally without a debugger
CP does NOT directly teach you:
- Code organization and architecture
- Working with APIs and frameworks
- Testing methodologies
- Team collaboration and code review
- System design and distributed systems
Both skill sets are valuable. Many top engineers were competitive programmers who then learned software engineering practices. Use CP as the foundation for your algorithmic thinking, but do not neglect engineering skills for your career.
Final Advice for Beginners
If I could give one piece of advice to my past self starting CP, it would be this: do not compare your progress to others. Some people reach Expert in 6 months; for others it takes 2 years. What matters is that you are improving relative to where you were last month. Track your own growth — the problems that were impossible last month should feel approachable this month. That is progress, and it compounds over time.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Competitive Programming Introduction.
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, introduction
Related Data Structures & Algorithms Topics