Level 1 Training

Build your algorithmic toolkit with two pointers, binary search, recursion, bitmasks, counting, and number theory. Trace the idea, check the conditions, and practice explaining why it works.

01
Session 1

Two pointers and binary search

Use sorted order, moving windows, and monotone decisions to eliminate repeated work. Prove each boundary movement before using a template.

01

Eliminate candidates with two pointers

Use the two ends of a sorted array to find a pair without checking every combination.

02

Find lower and upper bounds

Return a boundary first; decide separately whether it is an exact match.

03

Reuse progress across sorted sequences

Merge, sweep offline queries, and filter with forward-moving indices.

04

Slide a fixed-length window

Maintain a sum by removing one contribution and adding one contribution.

05

Grow and repair a variable window

Distinguish longest-under-budget from shortest-reaching-target windows.

06

Count windows and maintain frequencies

Count all valid starts, or store occurrences when a sum is not the right summary.

07

Binary-search a monotone answer

Turn optimization into a decision problem with a proved truth direction.

08

Prove the checker before searching

Connect greedy scans, capped arithmetic, and two-pointer counts to answer search.

02
Session 2

Recursion and backtracking

Describe one call, prove progress, and explore choices while restoring shared state. Separate correctness, call count, and stack depth.

01

Give one recursive call a contract

Separate the meaning of a call, its base case, and its progress toward termination.

02

Shrink an index, a number, or a range

Choose parameters that describe remaining work without copying it.

03

Count calls separately from stack depth

Distinguish a chain, a branching tree, and divide-and-conquer work.

04

Choose, explore, and undo

Generate decisions without letting one branch contaminate the next.

05

Match stopping and pruning to the question

Existence, one witness, counts, and enumeration need different return rules.

06

Generate combinations and permutations

Encode whether order matters, and avoid equivalent duplicate-value branches.

07

Reject impossible prefixes early

Use local validity rules for balanced parentheses and nonattacking queens.

08

Trace paths and recognize reusable states

Distinguish current-path visitation from permanent visitation and memoized answers.

03
Session 3

Bit manipulation and bitmasking

Give every bit a meaning. Use unsigned operations, XOR identities, compact sets, and subset enumeration with explicit width limits.

01

Read binary and choose a width

Separate numeric value, written representation, and the width of the type.

02

Check, set, clear, and toggle

Choose a bitwise operation from its one-bit truth table.

03

Count and isolate set bits

Derive low-bit operations and use C++ bit utilities with valid unsigned inputs.

04

Cancel equal values with XOR

Use occurrence promises to find one or two odd-frequency values.

05

Answer range XOR queries

Reuse prefix cancellation and the four-case XOR pattern for consecutive integers.

06

Represent small sets with masks

Model presence, union, intersection, and coverage without confusing frequency with membership.

07

Enumerate subsets and optimize a choice

Give every position one take-or-skip bit and evaluate each mask exactly once.

08

Visit submasks and larger bitsets

Choose between a machine-word mask, a fixed bitset, and an exponential search.

04
Session 4

Counting principles

Define one outcome, decide whether order and reuse matter, and count it exactly once. Derive formulas and protect intermediate arithmetic.

01

Add cases, multiply stages, subtract bad outcomes

Choose the counting operation from the structure of an outcome.

02

Arrange distinct objects and ordered roles

Derive factorials and falling products from choices without replacement.

03

Count unordered groups

Explain why dividing ordered selections by r! removes exactly the repeated orders.

04

Compute combinations with Pascal’s identity

Build exact or modular answers using addition instead of unsafe factorial division.

05

Choose groups, positions, and route steps

Translate different stories into precise combinations and independent stages.

06

Count contributions and correct overlap

Group equal pairs and derive inclusion-exclusion by tracking how often one object is counted.

07

Enumerate overlapping conditions

Use subset parity and LCM to count a union of divisibility conditions.

08

Handle repeated objects and arithmetic safely

Extend the model to repeated letters, circles, distributions, and exact calculations.

05
Session 5

Number theory - Part 1

Understand divisor pairs and prime exponents, then choose a sieve or factor table that matches the number and size of your queries.

06
Session 6

Number theory - Part 2

Connect common factors, modular arithmetic, fast powers, and inverses. Check the conditions that make division and shortcuts valid.

01

Preserve common divisors with Euclid

Replace a pair with a smaller equivalent pair until the remainder is zero.

02

Combine periods with a safe LCM

Divide first and guard the product that remains.

03

Keep residues and normalize them

Preserve remainders under addition and multiplication, and treat division separately.

04

Build powers by repeated squaring

Reuse binary exponent contributions for logarithmic work.

05

Check that an inverse exists

Use coprimality before extended Euclid or the prime-modulus shortcut.

06

Prepare modular combination tables

Use factorial inverses only under their prime and range conditions.

07

Handle several solutions and GCD summaries

Solve linear congruences and combine prefixes with suffixes.

08

Keep the arithmetic contract explicit

Connect totients, huge exponents, congruences, and division-free sums.

From a problem to a programIdentify the input, output, and constraints, then translate a small plan into C++.Variables, types, and remembered valuesChoose a representation, initialize it, and understand what assignment really changes.Arithmetic without surprisesPredict division and remainder, widen before multiplication, and format decimal answers.Conditions and logical decisionsBuild exclusive categories, combine comparisons, and protect operations with short-circuit logic.Optional: other ways to chooseRecognize switch for exact choices and the conditional operator for choosing a value.For loops: make repetition preciseTrace initialization, condition, body, and update—and avoid an extra iteration.While, do-while, and stopping rulesChoose a loop from its stopping condition and read the exact input format.Break, continue, and early answersDistinguish leaving a loop from skipping one iteration, without losing required input.Five patterns worth understandingUse sums, counts, best-so-far candidates, products, and flags to process a stream.Nested loops: rows and columnsTranslate a shape into two loop roles and count the total work.Take a number apart, one digit at a timeUse remainder and division to process decimal digits, including zero.Multiple cases and a debugging mindsetCombine the patterns, isolate each case, and test the boundaries that can break your idea.Arrays: give every value a placeUnderstand indices, initialization, capacity, active length, and the first safe array loop.Scan, count, search, and compareDistinguish values from positions and preserve the exact tie rule a problem asks for.Change a sequence without losing itUpdate, copy, compare, reverse, and inspect neighbours using the correct bounds.Matrices: think in two coordinatesTraverse tables, total rows and columns, inspect diagonals, and protect grid neighbours.Characters become stringsSeparate characters from numbers, then safely inspect and edit managed text.Read the text the problem actually givesChoose words or full lines, preserve empty cases, and reset only the state that needs it.Scan text: count, filter, transformBuild a result from matching characters without losing leading zeros or skipping shifted text.Join, compare, and find textLearn content comparison, lexicographical order, substring counts, and the not-found sentinel.