Skip to content

Topic 1 of 20

Foundations

Big-O, complexity analysis and the basic math every later topic leans on.

5 problems3 Easy2 Medium0 Hard

The concept

Before you learn any clever technique, learn to measure code. Big-O notation describes how an algorithm's running time or memory grows as its input grows. It ignores constants and focuses on the dominant term, so a loop over n items is O(n) and a loop inside a loop is O(n²). Interviewers expect you to state the time and space complexity of every solution you write, and to know when a brute force is "fast enough" (roughly 10⁸ simple operations per second is a good rule of thumb).

The problems in this topic are deliberately simple. Use them to build habits: read the constraints first, write the brute force, state its complexity, then ask "can I do better?". You will also practise the small arithmetic tricks, extracting digits with % 10 and / 10, and guarding against integer overflow, that appear again and again in later topics.

Solve each one, then write its complexity in your notes before moving on. That single habit is what separates candidates who "solved it" from candidates who can explain it.

Patterns you will learn

Problems, in order

  1. 1

    The classic warm-up: turns a spec into clean conditional logic and shows O(n) at its simplest.

    SimulationReported at: MetaMicrosoftApple
  2. 2

    Two nested loops over a grid: the gentlest possible introduction to O(m·n) analysis.

    Nested IterationReported at: Adobe
  3. 3

    Reversing half the digits with % and / is a trick reused in many number problems.

    Digit ManipulationReported at: GoogleMetaAmazon+5
  4. 4

    Adds 32-bit overflow detection to digit reversal, a detail interviewers love to probe.

    Digit ManipulationReported at: AmazonGoogleMeta+7
  5. 5

    Shows how a smarter algorithm turns O(n·√n) into O(n log log n); a first taste of optimisation.

    Sieve of EratosthenesReported at: AmazonMicrosoftApple+2