Skip to content
LeetQuant
QT02 Advanced Probability and Brainteasers

QT02 · Advanced Probability and Brainteasers · Lesson 2 of 5

The Brainteaser Toolkit

Invariants, parity, relabelling, information counting and the pigeonhole principle: the five ideas behind most logic puzzles.

25 min

What interviewers want from a brainteaser

Logic puzzles test whether you can find structure under time pressure. Most of them yield to one of five ideas. When you are stuck, try each in turn and say which you are trying.

  1. Invariants and parity. Find a quantity that never changes, and show the goal would change it.
  2. Relabelling and symmetry. Describe the same process in a way that makes it trivial.
  3. Information counting. Count how many outcomes must be distinguished and how many each test can separate.
  4. Pigeonhole. If n+1n + 1 objects go into nn boxes, two share a box.
  5. Small cases and extremes. Solve n=1,2,3n = 1, 2, 3, look for the pattern, then prove it.

Worked example

the mutilated chessboard

Remove two diagonally opposite corner squares from an 8×88 \times 8 chessboard. Can the remaining 62 squares be covered by 31 dominoes, each covering two adjacent squares?

Show solution

No. Every domino covers one black and one white square, so any tiling covers equally many of each. Opposite corners have the same colour, so the board has 32 squares of one colour and 30 of the other. The colour count is the invariant.

Relabelling

Some processes look complicated only because we track the wrong objects. In the classic ant puzzle, two ants bouncing off each other look exactly like two ants passing through each other with their labels swapped. If you only care about when the last ant leaves, labels do not matter, so you may pretend the ants pass through each other and each walks straight off the end.

Similar tricks: in a knockout tournament with nn players, every game eliminates exactly one player, so there are always n−1n - 1 games. To count handshakes, count ordered pairs and halve.

Information counting

If a test has kk possible results, then mm tests can distinguish at most kmk^m cases. This gives a lower bound on the number of tests, and often a hint for the construction.

A balance scale has three results (left heavy, right heavy, balanced). Finding one heavier coin among 9 needs at least ⌈log⁡39⌉=2\lceil \log_3 9 \rceil = 2 weighings, and two suffice: weigh 3 against 3, then 1 against 1 within the heavy group (or the unweighed group if balanced).

For the famous 12-coin problem (one coin is heavier or lighter), there are 12×2=2412 \times 2 = 24 cases and 33=27≥243^3 = 27 \ge 24, so three weighings might work, and they do, with careful design. A yes/no question has 2 results, so it can at most double your chance of guessing a hidden outcome.

Pigeonhole and extremes

Pigeonhole: among any 5 points in a unit square, two are within 22\tfrac{\sqrt2}{2} of each other. Divide the square into four quarter-squares; two points share one, and the diagonal of a quarter is 22\tfrac{\sqrt2}{2}.

Extremes and burning tricks: a rope that burns in 60 minutes, lit at both ends, burns out in exactly 30 minutes however unevenly it burns, because the two flames together consume the whole rope's worth of burning time. Look for an operation that removes the unknown.

Small cases: "how many pieces from nn straight cuts?" Count 1, 2, 4, 7 and notice the kk-th cut can add at most kk pieces, since it crosses at most k−1k - 1 earlier cuts.

Worked example

the hands of a clock

How many times in 24 hours do the hour and minute hands of a clock point in exactly the same direction?

Show solution

The minute hand turns at 360° per hour and the hour hand at 30° per hour, so the minute hand gains a full lap on the hour hand every 360330=1211\tfrac{360}{330} = \tfrac{12}{11} hours. In 24 hours that happens 24×1112=2224 \times \tfrac{11}{12} = 22 times. (The overlap at midnight is counted once.)

Knowledge check

100 lockers start closed. Person k toggles every k-th locker, for k = 1 to 100. How many lockers are open at the end?

Knowledge check

One of 27 coins is heavier than the rest. What is the minimum number of weighings on a balance scale that guarantees finding it?

Knowledge check

A single-elimination tennis tournament has 113 players, with byes as needed. How many matches are played?

Practice problems

Finished reading?

Answer the 3 knowledge checks to complete this lesson (0 done).