← Questions

N-th license plate in sorted order

0
GoogleCodingLast asked Jun 2025

A coding interview question asked in Google's onsite coding round, last asked Jun 2025. It tests math and combinatorics.

A license plate has exactly six characters: three uppercase letters A to Z, then three digits 0 to 9 (for example AAA000 or BCD123). List every possible plate in dictionary order. Given a 1-indexed n, return the n-th plate directly, without generating the list.

Interface

Unless you agree on a different interface with the interviewer, assume:

  • nth_plate(n: int) -> str — for 1 <= n <= 26^3 · 10^3 = 17,576,000; raise ValueError outside that range.

Example

nth_plate(1)          ->  "AAA000"
nth_plate(1000)       ->  "AAA999"    # the first 1000 plates all start with AAA
nth_plate(1001)       ->  "AAB000"
nth_plate(27001)      ->  "ABB000"    # index 27000 = 27 letter blocks: A, B, B
nth_plate(123456)     ->  "AET455"
nth_plate(17576000)   ->  "ZZZ999"

Constraints

  • O(1) time and space; no enumeration.

Clarifying questions

  • Is n 1-indexed?
  • Does "lexicographic" mean plain string order? (Here it matches the numeric order of a mixed-radix number, because letters come before digits in every plate.)
  • What should happen for n out of range?
  • Could the format change, for example to LLDDDL?

What a strong answer covers

  • Convert to a zero-based index i = n - 1, then split it: letters, digits = divmod(i, 1000). The digits are digits padded to three places; the letters are letters written in base 26 with three places, A as 0.
  • Why this is the same as dictionary order: every plate has the same length and the same letter-then-digit layout, so string order is the order of the mixed-radix number.
  • Bounds checks and an off-by-one test at each block boundary (999 to 1000, 25,999 to 26,000).
  • A brute-force check over a smaller alphabet to validate the formula.

Follow-ups

  • Generalise to any format string such as LLDDDL (a mixed radix taken position by position).
  • Some letters (I, O) are never used on plates.
  • The reverse: given a plate, return its index.

Where it's asked

  • Google · Onsite coding · Last asked Jun 202545 min · Usually two rounds, mostly in person: whiteboard plus a Chromebook with Google Docs · No AI (a pilot code-comprehension round lets candidates use Gemini)

What it tests

math · combinatorics

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding