What is problem solving?
Problem solving in competitive programming means reading a well-defined problem, understanding its constraints, designing an algorithm, and writing code that produces the correct output for all valid inputs — within time and memory limits.The problem-solving process
Every problem follows the same workflow:Read and understand
Read the problem statement carefully. Identify the input format, output format, and constraints. Re-read if anything is unclear.
Work through examples
Trace through the sample test cases by hand. Make sure you understand why the expected output is correct.
Design your approach
Think about the algorithm before writing code. Ask yourself: what data structure do I need? What’s the time complexity?
Input and output in C++
The most basic skill — reading input and writing output efficiently.Data types and their limits
Choosing the right data type prevents overflow bugs:| Type | Size | Range | When to use |
|---|---|---|---|
int | 4 bytes | ≈ ±2.1 × 10⁹ | Most problems |
long long | 8 bytes | ≈ ±9.2 × 10¹⁸ | When n > 10⁹ or products/sums can overflow |
double | 8 bytes | ~15 decimal digits | Floating point problems |
char | 1 byte | -128 to 127 | Single characters |
bool | 1 byte | true/false | Flags |
Basic math operations
Simple problem patterns
Pattern 1: Process and output
Read input, do some calculation, print the result.Pattern 2: Count something
Count how many elements satisfy a condition.Pattern 3: Find min/max
Track the minimum or maximum as you iterate.Practice
Head over to Sheet 1 — Intro to PS to practice these concepts with curated problems.Sheet 1: Intro to PS
Practice problems for this tutorial.