Practice & Problem Solving

Master competitive programming through coding challenges and develop algorithmic thinking with logic puzzles.

Coding Problems

Practice with curated problems from Codeforces, organized by difficulty. Build your skills from beginner to advanced.

Coding Tips

  • Start with problems at your current skill level, then gradually increase difficulty
  • Try to solve each problem on your own before looking at hints or solutions
  • After solving, analyze the time and space complexity of your solution
  • Revisit problems you couldn't solve after learning new concepts

Beginner Problems

Perfect for those just starting their competitive programming journey.

Watermelon

Beginner

Determine if a watermelon can be divided into two even parts.

Math Brute Force
800 500k+ solved
Solve Problem

Way Too Long Words

Beginner

Abbreviate words that are too long according to specific rules.

Strings Implementation
800 400k+ solved
Solve Problem

Team

Beginner

Count problems that can be solved by a team of three friends.

Brute Force Greedy
800 350k+ solved
Solve Problem

Next Round

Beginner

Determine how many participants advance to the next round.

Implementation
800 300k+ solved
Solve Problem

Easy Problems

Build confidence with basic algorithmic thinking.

Nearly Lucky Number

Easy

Check if the count of lucky digits is itself a lucky number.

Implementation Strings
800 200k+ solved
Solve Problem

Petya and Strings

Easy

Compare two strings lexicographically, ignoring case.

Strings Implementation
800 280k+ solved
Solve Problem

Bear and Big Brother

Easy

Calculate when Limak's weight will exceed Chantel's weight.

Math Implementation
800 170k+ solved
Solve Problem

Elephant

Easy

Find minimum steps for an elephant to reach position X.

Math Greedy
800 160k+ solved
Solve Problem

Medium Problems

Challenge yourself with sorting, searching, and simulation problems.

Twins

Medium

Find minimum coins needed to have strictly more than your twin.

Greedy Sorting
900 120k+ solved
Solve Problem

Queue at the School

Medium

Simulate a queue of boys and girls swapping positions.

Implementation Simulation
1000 100k+ solved
Solve Problem

Two-gram

Medium

Find the most frequent two-character substring.

Strings Implementation
900 90k+ solved
Solve Problem

Gravity Flip

Medium

Simulate boxes falling in a container after gravity flips.

Sorting Greedy
900 85k+ solved
Solve Problem

Hard Problems

Advanced algorithms, graphs, and dynamic programming.

Longest Regular Bracket Sequence

Hard

Find the longest valid parentheses substring and count occurrences.

Stack DP Strings
1900 25k+ solved
Solve Problem

Two Buttons

Hard

Find minimum button presses to transform one number to another.

BFS Greedy Math
1400 45k+ solved
Solve Problem

Mike and Shortcuts

Hard

Find shortest paths using BFS with special edges.

Graphs BFS
1600 18k+ solved
Solve Problem

Powerful Array

Hard

Answer range queries using Mo's algorithm efficiently.

Mo's Algorithm Data Structures
2200 5k+ solved
Solve Problem

More Practice Resources

Explore these platforms for additional problems.

Codeforces

Popular competitive programming platform with regular contests.

Visit

AtCoder

High-quality problems and beginner-friendly contests.

Visit

CSES Problem Set

Curated collection for systematic practice.

Visit

LeetCode

Great for interview preparation.

Visit

Logic & Reasoning

Develop algorithmic thinking through puzzles. No coding required — focus on problem-solving strategies.

Problem Solving Framework

1
Understand

Identify inputs, outputs, constraints

2
Plan

Break into smaller parts

3
Explore

Try examples, find patterns

4
Solve

Design step-by-step approach

5
Reflect

Optimize and learn

Classic Logic Puzzles

Foundational puzzles that teach core problem-solving patterns.

The Weighing Problem

Binary Search
Problem

You have 8 identical-looking balls. One ball is slightly heavier than the others. Using a balance scale, what is the minimum number of weighings needed to guarantee finding the heavy ball?

Think about dividing balls into groups. Each weighing gives three outcomes: left heavier, right heavier, or balanced.

Answer: 2 weighings

Approach: Divide and Conquer (Ternary Search)

  1. Divide into 3 groups: A(3), B(3), C(2)
  2. Weighing 1: Compare A vs B → identifies which group has heavy ball
  3. Weighing 2: Compare 2 balls from that group → finds the heavy one

Key Insight: With n weighings, you can distinguish 3ⁿ cases. 3² = 9 ≥ 8 balls.

Divide & Conquer Optimization Information Theory

Water Jug Problem

State Space Search
Problem

You have a 5-liter jug and a 3-liter jug with no measuring marks. How do you measure exactly 4 liters of water?

Think of each state as (water in 5L, water in 3L). What operations can you perform?

Solution Steps
(0, 0) Start: both empty
(5, 0) Fill 5L jug
(2, 3) Pour into 3L jug
(2, 0) Empty 3L jug
(0, 2) Pour 5L into 3L
(5, 2) Fill 5L jug
(4, 3) Pour into 3L until full ✓

Key Insight: This is a graph problem! BFS finds the shortest path.

BFS State Space Graph Traversal

Monty Hall Problem

Probability
Problem

3 doors: one has a car, two have goats. You pick a door. The host opens another door showing a goat. Should you switch or stay?

What's the probability the car was behind your first choice? What about the other doors combined?

Always Switch! (2/3 win rate)

Case Analysis:

  • Pick car (1/3) → Switch loses
  • Pick goat A (1/3) → Switch wins
  • Pick goat B (1/3) → Switch wins

Key Insight: Your initial choice had 1/3 probability. The remaining 2/3 concentrates on the other unopened door.

Probability Conditional Logic Enumeration

Algorithmic Thinking

Problems about efficiency, optimization, and algorithm design.

The Staircase Problem

Dynamic Programming
Problem

You can climb stairs by taking 1 or 2 steps at a time. How many different ways can you climb n steps?

To reach step n, you must have come from n-1 or n-2. How do these relate?

Answer: Fibonacci Sequence!
f(1) = 1, f(2) = 2
f(n) = f(n-1) + f(n-2)
f(3) = 3, f(4) = 5, f(5) = 8...

Key Insight: This is dynamic programming — combining solutions to subproblems.

Dynamic Programming Recurrence Fibonacci

Find the Missing Number

Mathematical Insight
Problem

You have n-1 distinct integers from 1 to n (one missing). Find it in O(n) time and O(1) space without sorting.

You know what the sum of 1 to n should be...

Use the Sum Formula
Expected = n(n+1)/2
Actual = sum of given list
Missing = Expected - Actual

Alternative: XOR all numbers 1 to n with all elements. Result = missing number.

Math XOR Space Optimization

Coin Change Greedy Trap

Greedy vs DP
Problem

Coins: [1, 3, 4]. What's the minimum coins for 6 cents? Does greedy (always pick largest) work?

Greedy: pick 4, then what? Try 3+3 instead.

Greedy Fails! Answer: 2 coins

Greedy: 4 + 1 + 1 = 3 coins ❌

Optimal: 3 + 3 = 2 coins ✓

Lesson: Greedy doesn't always work. When in doubt, use DP.

Greedy Dynamic Programming Counter-Example

Strategy & Optimization

Making optimal decisions and understanding trade-offs.

The Egg Drop Problem

Optimization
Problem

2 eggs, 100 floors. Find the highest safe floor. What's the minimum drops needed in worst case?

If egg breaks at floor k, you have 1 egg for floors 1 to k-1 (linear search). Balance worst cases!

Answer: 14 drops

Drop from floors: 14, 27, 39, 50, 60, 69, 77, 84, 90, 95, 99, 100

Each step decreases by 1 because you've used one drop.

Math: n + (n-1) + ... + 1 ≥ 100 → n = 14

Dynamic Programming Optimization Worst-Case Analysis

River Crossing Puzzle

Constraint Satisfaction
Problem

Farmer with wolf, goat, cabbage. Boat fits farmer + 1 item. Wolf eats goat, goat eats cabbage if left alone. Get all across safely.

The goat can't be left with either. Sometimes you need to bring something back!

7 Crossings
Take goat → [W,C] | [G]
Return alone
Take wolf → [C] | [W,G]
Bring goat back → [C,G] | [W]
Take cabbage → [G] | [W,C]
Return alone
Take goat → [] | [W,G,C] ✓

Key Insight: Backtracking is necessary!

Constraint Satisfaction Backtracking State Space

Tower of Hanoi

Recursion
Problem

3 pegs, n disks on peg A (smallest on top). Move all to C. Rules: move one at a time, never place larger on smaller. Minimum moves?

To move n disks A→C: First move top (n-1) to B, then bottom to C, then (n-1) from B to C.

Answer: 2ⁿ - 1 moves

Recurrence: T(n) = 2T(n-1) + 1

n=1: 1 | n=2: 3 | n=3: 7 | n=4: 15 | n=5: 31

Key Insight: Classic example of recursive problem decomposition.

Recursion Recurrence Relations Exponential Growth