← Questions
N-th license plate in sorted order
0
I was asked this
No reports yet. Sign in to say where you were asked it.
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— for1 <= n <= 26^3 · 10^3 = 17,576,000; raiseValueErroroutside 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
n1-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
nout 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 aredigitspadded to three places; the letters areletterswritten in base 26 with three places,Aas 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
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
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
