Nth Staged License Plate
Updated
Problem statement
License plates all have the same total length length, and they are made in stages. A plate in stage k starts with exactly k uppercase letters, followed by length - k digits. The stages come one after another, from k = 0 up to k = length.
Inside one stage, read the letter part as a base-26 number where A = 0, padded on the left with A to its full width. Read the digit part as a normal base-10 number, padded on the left with zeros. Plates in a stage are listed by their letter part first, and then by their digit part.
Put all the stages in a row and number the plates from zero. Return the plate at index n. The index n counts from zero.
Function
nthStagedLicensePlate(n: long, length: int) → StringExamples
Example 1
n = 0length = 5return = "00000"Index zero is the very first plate. The first stage has only digits, and its first plate is all zeros.
Example 2
n = 99999length = 5return = "99999"This is the last plate of the digits-only stage, so every digit is a nine.
Example 3
n = 100000length = 5return = "A0000"The digits-only stage fills the first 100000 indexes. The next plate opens the one-letter stage: an A followed by four zeros.
Example 4
n = 360length = 2return = "AA"With length two, the digits-only stage has 100 plates and the one-letter stage has 260. Those all come first, so this index is the first plate of the all-letter stage, which is AA.
Constraints
1 <= length <= 10.0 <= n < sum(26^k * 10^(length-k))for0 <= k <= length.- All intermediate counts fit in a signed 64-bit integer.
More Google Onsite Interview questions
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Iterate Canonical IPv6 AddressesOpenAI · ONSITE INTERVIEWOpenAI interview questions
- Add Decimal Strings ExactlyMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Add Two Numeric Strings with CarryZipRecruiter · ONSITE INTERVIEWZipRecruiter interview questions
- Add Two Numbers Given as Digit ArraysCapital One · ONSITE INTERVIEWCapital One interview questions
- Add Signed Character ArraysByteDance · PHONE SCREENByteDance interview questions
- Per-Segment SpeedingOnePay · PHONE SCREENOnePay interview questions
- Flip Rows and Columns, Count ZerosNutanix · OANutanix interview questions
- Format a Centered Pagination BarMixpanel · PHONE SCREENMixpanel interview questions
- Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
- Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions