##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Explore individual topics with detailed lessons and practice problems.
Learn the building blocks: operations, order of operations (PEMDAS), and modular arithmetic basics.
The Goal
Addition through division
PEMDAS rules
Knowledge check
Discarding the remainder
Rounding down
Rounding up
Getting the remainder
Concrete calculations
Knowledge check
Using modulo 2
Wrapping around
Addition and multiplication
Preventing overflow
Language differences
Knowledge check
LeetCode 231
Repeated division by 2
Step by step approach
In pseudocode
Tracing an example
summary
Using modulo 10
Remainder when dividing by 10
Repeated modulo and division
LeetCode 412
Checking divisibility
In pseudocode
summary
LeetCode 258
Straightforward method
Modulo 9 pattern
In pseudocode
summary
Practical applications
Practical decision making
Pitfalls to watch for
Knowledge check
LeetCode 202
Detecting cycles
What we learned
Powers, roots, and exponent rules. Learn x^a × x^b = x^(a+b) and how to simplify expressions.
The Goal
Repeated multiplication
The two parts
Building intuition
Knowledge check
Always equals 1
Just the base
Adding exponents
Subtracting exponents
Multiplying exponents
Knowledge check
Reciprocal of positive power
Roots in disguise
Inverse of squaring
Generalizing roots
Practical applications
LeetCode 50
Loop n times
Squaring reduces work
Breaking down the exponent
Fast exponentiation
Tracing the algorithm
summary
Integers with integer roots
LeetCode 367
Finding the root
Binary search solution
summary
Computing large powers
Fast exponentiation with mod
Iterative approach
Bit-by-bit squaring
Tracing the algorithm
summary
LeetCode 1922
Positions alternate
Half positions, ceiling trick
Using modular exponentiation
summary
LeetCode 372
Decomposition trick
Apply modulo properties
Recursive approach
summary
Knowledge check
Powers of 2
Algorithm complexity
Powers of 2 everywhere
Floating-point issues
What we learned
What logarithms are, key properties, common vs natural log, and why O(log n) appears everywhere in CS. The inverse of exponentiation.
The Goal
Undoing exponentiation
Base and argument explained
Test your understanding
Most common in CS
Scientific notation base
Calculus and growth rates
Any base equals zero
Always equals one
First logarithm property
Second logarithm property
Third logarithm property
Test your understanding
Switch between any bases
All logarithms are equivalent
Divide and conquer
Halving the search space
Balanced binary trees
Test your understanding
LeetCode 50
Halve the exponent
Recursive solution
Time and space breakdown
What you learned
LeetCode 35
Find or insert position
Binary search solution
Step-by-step example
What you learned
LeetCode 279
Building from smaller values
DP solution
Why logs appear
What you learned
Tree height analysis
Balanced partitions
Heap operations
Test your understanding
LeetCode 378
Count elements below threshold
Binary search solution
What you learned
Binary representation
Counting digits
Test your understanding
Why log n is fast
Call stack usage
What to watch out for
What we learned
Variables, solving equations, substitution, inequalities, and when the inequality sign flips. The language of algorithms.
The Goal
Representing unknowns
Combination of numbers and variables
Statement of equality
The golden rule
Isolating the variable
Knowledge check
Replacing variables with values
Simplifying expressions
Expanding expressions
Reverse of distribution
Knowledge check
Greater than and less than
Negative multiplication rule
Solving quadratic equations
Determining solution count
Multiple equations together
Replace one variable
Adding or subtracting equations
Knowledge check
LeetCode 1
What you're solving
Efficient lookup
In pseudocode
summary
LeetCode 367
What you're checking
Narrowing the range
In pseudocode
summary
LeetCode 11
Maximizing area
Greedy approach
Proof sketch
In pseudocode
summary
Simplifying runtime formulas
Recursive algorithm analysis
Finding loop bounds
Knowledge check
Proving bounds
Formulas you'll see often
LeetCode 268
LeetCode 69
LeetCode 53
What we learned
You know arithmetic and exponents. Now learn arithmetic and geometric sequences with summations.
The Goal
Ordered lists of numbers
How to write sequences
Constant difference pattern
Finding the 50th term
Knowledge check
Constant ratio pattern
Powers of two
Sigma notation basics
Expanding sigma notation
The famous formula
Knowledge check
Sum of arithmetic sequence
Sum of geometric sequence
Common pattern in algorithms
Sum explains the complexity
When terms cancel
Fraction sum
Knowledge check
LeetCode 303
Precompute cumulative sums
In pseudocode
summary
LeetCode 413
How many slices in a sequence
Track consecutive arithmetic elements
In pseudocode
summary
LeetCode 279
Building from smaller values
Loop bounds from sequence
In pseudocode
summary
Reference sheet
Algebraic rules for sums
Knowledge check
When ratio is less than 1
LeetCode 1137
LeetCode 70
LeetCode 633
What we learned
Binary, octal, hexadecimal, and decimal. Converting between bases. Why binary is fundamental to computing.
Why number bases matter
Core concept
Base-10 familiar ground
Base-2 system
Physical limitations
Reading binary numbers
Knowledge check
Writing binary numbers
Memorize these
Base-16 system
Hex to decimal mapping
Real-world usage
Grouping by fours
Knowledge check
Base-8 basics
Universal method
Arithmetic in base-2
Borrowing in base-2
Sign magnitude approach
Standard for negatives
Decoding negative values
Knowledge check
LeetCode 191
Shift and mask
Flip rightmost 1
Pseudocode solution
LeetCode 190
Shift and accumulate
Pseudocode solution
AND OR XOR NOT
Knowledge check
Useful patterns
LeetCode 231
Single 1 bit
One-line check
LeetCode 67
Managing carry
Pseudocode solution
Built-in functions
summary
What we learned
Bitwise AND, OR, XOR, NOT, and shifts. Checking, setting, clearing, and toggling bits. The foundation for bitmask techniques.
What bit manipulation is
Binary foundation
Reading binary numbers
Both bits must be 1
At least one bit is 1
Bits differ
Flip all bits
Multiply by powers of 2
Divide by powers of 2
Knowledge check
Test individual bits
Turn a bit on
Turn a bit off
Flip a bit
Quick reference
LeetCode 191
Loop through all bits
Clever bit trick
The code
Knowledge check
One-line trick
LeetCode 231
The code
Another useful trick
Magic of XOR
LeetCode 136
XOR cancellation
The code
Knowledge check
Representing sets as bits
Generate all subsets
Union, intersection, difference
LeetCode 78
Using bit manipulation
The code
Knowledge check
XOR swap trick
Mirror the bits
Quick reference
Recognizing the pattern
What we learned
True/False, AND, OR, NOT, XOR, truth tables, logical equivalences, and De Morgan laws. The foundation of programming conditions.
What boolean logic is and why it matters
Core concept
Literal values
Storing true/false
Both must be true
All combinations
At least one true
All combinations
Flips the value
Simple flip
Knowledge check
Complex expressions
Order matters
Exclusive OR
Different inputs
Skipping unnecessary work
Negating complex expressions
Concrete application
Knowledge check
Rewriting expressions
LeetCode 20
Stack matching
The code
LeetCode 231
Single bit set
The code
Knowledge check
If statements
Loop conditions
LeetCode 448
In-place marking
The code
LeetCode 136
XOR cancellation
The code
Knowledge check
Transformation rules
Simplification rules
What to avoid
What we learned
Learn what sets are, how to write them, and set operations: union, intersection, and difference.
Why sets matter
Unordered unique collection
Curly braces
Member of a set
Set with nothing
Defining with rules
Number of elements
All elements contained
Subset but not equal
Same elements
Combine both sets
Common elements only
Elements in first only
Everything not in set
Either set not both
Visual representation
Set of all subsets
Complement identities
Hash sets and tree sets
Knowledge check
LeetCode 349
Membership check
Hash set solution
summary
LeetCode 2215
Two-way difference
Two set subtractions
summary
Knowledge check
LeetCode 645
Frequency tracking
Frequency array
summary
LeetCode 128
Start of sequence
Counting forward
Smart iteration
summary
Knowledge check
Problem patterns
What we learned
The sum rule and product rule. When to add vs when to multiply. The foundation for all combinatorics.
(The Goal)
(Algorithms need to know how many)
(Add when choices are separate)
(Choosing a programming language)
(Multiply when choices are independent)
(Building a username)
(The decision framework)
(Combining both rules)
(Simple product rule application)
(26^4 = 456,976)
(Adding constraints)
(Classic DP problem)
(LeetCode 62)
(Paths through each cell)
(DP recurrence)
(Python tabulation)
(Character combinations)
(LeetCode 17)
(Product of set sizes)
(Backtracking approach)
(Exponential in worst case)
(Knowledge check)
(Exclude certain cases)
(Common restriction pattern)
(Count the same set two ways)
(More items than containers)
(Identical hash values)
(Count overlapping sets)
(Students in clubs)
(Real algorithm problems)
(Ordered counting)
(Restrictions and principles)
When simple rules fail
The power of 2
Direct application
Subtract what you cannot use
Using prime factorization
Counting paths with steps
Recursive structure
The pseudocode
(LeetCode 62 - Grid paths)
(Sum of incoming paths)
(2D DP table)
(Grid counting principles)
(LeetCode 63 - Obstacles)
(Setting blocked cells to 0)
(Modified DP with checks)
(Counting with constraints)
(LeetCode 17 - Product rule)
(Product rule application)
(Backtracking generation)
(Product rule in practice)
What we learned
n! factorial, arranging objects in order, permutations with and without repetition. Counting ordered arrangements.
(The Goal)
(Arrangements vs selections)
(Building intuition)
(n! means n × (n-1) × ... × 1)
(Multiplying choices)
(Computing by hand)
(The basic formula)
(Choosing r from n)
(Permutations formula)
(Computing permutations)
(Replacing items)
(n^r arrangements)
(Passwords and codes)
(Identical items)
(Dividing by repetitions)
(Anagrams with repeats)
(Arranging in a circle)
((n-1)! arrangements)
(Round tables and necklaces)
(Rearranging letters)
(Words with repeats)
(No element in original find)
(D(n) recursive formula)
(D(n) ≈ n!/e)
(Knowledge check)
(LeetCode 46)
(Backtracking strategy)
(Recursive backtracking)
(Python solution)
(LeetCode 60)
(Factorial number system)
(Greedy construction)
(Direct computation)
(Knowledge check)
(LeetCode 47)
(Skipping duplicates)
(Backtracking with pruning)
(Duplicate pruning)
(General template)
(LeetCode 31)
(LeetCode 784)
(LeetCode 526)
(Counting possibilities)
(Biological permutations)
(What you learned)
Find lexicographically next
Find the pivot point
The pseudocode
What we learned
Choosing without order, n choose k (C(n,k)), binomial coefficients, and Pascal triangle basics.
(The goal)
(The core idea)
(The critical difference)
(C(n,k) defined)
(Removing duplicates)
(Computing step by step)
(Another computation)
(Choosing vs leaving)
(Edge values)
(Visual representation)
(Row by row)
(The recursive formula)
(Algebraic verification)
(Expanding (a+b)^n)
((x+y)^3)
(Total is 2^n)
(Binary choice argument)
(Stars and bars)
(Visual explanation)
(Knowledge check)
(LeetCode 77)
(Building combinations recursively)
The pseudocode
(Python code)
(LeetCode 78)
(Backtracking pattern)
The pseudocode
(Python code)
(Knowledge check)
(LeetCode 39)
(Allow reuse)
The pseudocode
(Python code)
(Useful formulas)
(Diagonal sums)
Generate C(n,k)
(Where combinations appear)
Choose or skip pattern
(Avoiding overflow)
The pseudocode
(For competitive programming)
summary
(Final check)
Target sum with reuse
(Counting outcomes)
Same index or skip
Subsets with duplicates
The pseudocode
Skip duplicates
summary
The pseudocode
All possible subsets
What we learned
Decision tree approach
The pseudocode
summary
Sample space, events, P(A or B), P(A and B), complement rule, and independent vs dependent events.
(The Goal)
(All possible outcomes)
(Individual results)
(Subsets of the sample space)
(Favorable over total)
(Probability of rolling > 4)
(Always between 0 and 1)
(Probability of "not A")
(At least one head in 3 flips)
(A or B happens)
(P(A or B) formula)
(A and B both happen)
(Card draw probabilities)
(Cannot happen together)
(Rolling 2 or 5)
(One does not affect the other)
(P(A and B) for independent events)
(Two dice rolls)
(One affects the other)
(Probability given something happened)
(Cards without replacement)
(Works for dependent events)
(Knowledge check)
(Average outcome over many trials)
(Weighted average)
(Fair six-sided die)
(Different probabilities)
(Why probability matters)
(Using probability for speed)
(Birthday paradox in hash tables)
(Read statement)
(36 outcomes)
(Sum equals 7)
(P = 1/6)
(Read statement)
(Easier to count no match)
(Multiply probabilities)
(Why it is surprising)
(LeetCode 528)
(Convert weights to ranges)
(Build cumulative array)
(Find the range)
(Python code)
(Knowledge check)
(Apply what you learned)
Uniform random selection
Reservoir sampling idea
The pseudocode
Fair randomization
The standard solution
The code
summary
Weighted random selection
Converting weights to ranges
Finding the target range
The code
summary
Reservoir sampling variant
Fair selection in one pass
The code
summary
What we learned
Learn divisibility rules, factors, multiples, prime numbers, and the Sieve of Eratosthenes.
(The Goal)
(When division leaves no remainder)
(Two sides of divisibility)
(Last digit even)
(Last digit 0 or 5)
(Last digit 0)
(Sum of digits divisible by 3)
(Sum of digits divisible by 9)
(Last two digits divisible by 4)
(Only two factors)
(More than two factors)
(Breaking down into primes)
(Unique prime factorization)
(Check up to square root)
(Loop to square root)
(Check divisors up to square root)
(Knowledge check)
(Ancient algorithm for primes)
(Finding primes up to 30)
(Boolean array approach)
(Start at p squared)
(Entry problem)
(Use the sieve)
(Sieve then count)
(Implementation ready)
(Prime factors check)
(Divide out allowed primes)
(Divide and check remainder)
(Implementation ready)
(Sum of proper divisors)
(Find divisors efficiently)
(Sum proper divisors)
(Implementation ready)
(Knowledge check)
(Largest shared factor)
(Smallest shared multiple)
(Where these concepts appear)
(Knowledge check)
(Infinitely many)
(GCD equals 1)
Find the biggest prime
The key observation
Step by step approach
The pseudocode
What we learned
You've learned GCD and LCM. Now see why these numbers appear everywhere in competitive programming.
The Goal
Common divisors
Common multiples
Listing all divisors
Fast GCD computation
Implementation pattern
The core idea
Shorter code
The formula
Prime factorization view
Extending the algorithm
Knowledge check
LeetCode 1071
Length relationship
Two-step check
Implementation
GCD application
LCM application
LeetCode 878
Inclusion-exclusion principle
Finding the answer
Implementation
Knowledge check
Finding coefficients
Backtracking through steps
When GCD equals 1
Useful identities
LeetCode 1201
Counting with three sets
Finding the answer
Implementation
Knowledge check
Problem patterns
Problem patterns
The connection
Absolute values
Folding from left
Folding and overflow
Stein algorithm
LeetCode 1979
LeetCode 2709
Knowledge check
Add fractions using GCD
Common denominator approach
Parse and compute
The pseudocode
What we learned
Clock arithmetic and mod properties. You will see why mod 10^9 + 7 appears in contests and how to compute huge powers without overflow.
(The Goal)
(Time wraps around 12)
(Remainder after division)
(Language differences matter)
(Same remainder means equal)
(Add then mod, or mod then add)
(Multiply then mod, or mod then multiply)
(Watch for negative results)
(Overflow prevention)
(Check if number is power)
(Repeated division by 2)
(Loop until n becomes 1)
(15 lines)
(Knowledge check)
(Take mod at each step)
(Digital root via mod 9)
(Loop until single digit)
(Digital root and mod 9)
(O(1) formula)
(3 lines)
(Knowledge check)
(Computing large powers)
(Computing 2^10)
(Binary exponentiation)
(LeetCode 50)
(Handle negative exponent)
(Fast exponentiation with negatives)
(12 lines)
(Division in modular arithmetic)
(Inverse of 3 mod 7)
(Knowledge check)
(Values you see often)
(Why mod is not optional)
(LeetCode 202)
(LeetCode 326)
(LeetCode 171)
(LeetCode 400)
(Knowledge check)
(Beyond contests)
(What to avoid)
(When your mod code fails)
Modular exponentiation challenge
Break down large exponents
Digit by digit computation
The pseudocode
What we learned
Learn the coordinate plane, Pythagorean theorem, distance formulas, and basic triangle properties.
(The Goal)
(Two axes for positioning)
(Sign patterns by region)
(Pythagorean theorem applied)
(Right triangle relationship)
(Integer right triangles)
(Grid-based movement)
(Knowledge check)
(Entry problem introduction)
(Triangle inequality)
(Pseudocode walkthrough)
(Implementation ready)
(Width times height)
(Sum of all sides)
(Base times height divided)
(Pi times radius squared)
(Rise over run)
(Same line check)
(Knowledge check)
(Overlapping rectangles)
(Subtract overlap once)
(Step by step process)
(Implementation ready)
(Closed shapes with sides)
(Polygon area from vertices)
(Cells and coordinates)
(Transforming coordinates)
(Center between two points)
(Slope relationships)
(Knowledge check)
(Harder geometry validation)
(Distance pattern)
(Distance set approach)
(Implementation ready)
(Smallest enclosing polygon)
(Approximation via shapes)
(Enclosing rectangles)
(Floating point issues)
(Common techniques)
(Knowledge check)
Find rectangle from points
Diagonal points approach
Check all diagonal pairs
The pseudocode
What we learned
Measuring algorithm speed. Why constants vanish. The complexity classes.
(Why speed matters)
(Why execution time varies)
(The key variable)
(Worst-case upper bound)
(Growth patterns matter)
(Highest power dominates)
(No loops needed)
(Array access)
(One pass through data)
(Finding maximum)
(Analyzing linear scan)
(Single pass suffices)
(Loop and compare)
(Implementation structure)
(Nested loops)
(Checking all pairs)
(Knowledge check)
(Halving search space)
(Binary search)
(Efficient sorting)
(Merge sort)
(Trying all subsets)
(Naive Fibonacci)
(All permutations)
(Ranked by speed)
(Counting loops)
(Addition rule)
(Multiplication rule)
(Comparing O(n²) vs O(n))
(Hash map lookups)
(Single pass with map)
(Hash map approach)
(Memory usage)
(Call stack depth)
(Knowledge check)
(Average over sequence)
(When Big O varies)
(Analyzing logarithmic search)
(Divide and conquer)
(Shrinking window)
(Iterative implementation)
(Quick heuristics)
(Real-world tradeoffs)
(Knowledge check)
Compare time complexities
Three approaches
Hash set approach
The pseudocode
What we learned