Nth Staged License Plate
Problem statement
License plates are generated in stages for a fixed total length length. Stage k has exactly k leading uppercase letters followed by length - k digits. Stages run from k = 0 through k = length.
Within one stage, enumerate the letter prefix as a zero-padded base-26 number with A = 0, then enumerate the digit suffix as a zero-padded base-10 number. The index n is zero-based across the concatenation of all stages. Return the plate at index n.
Function
nthStagedLicensePlate(n: long, length: int) → StringExamples
Example 1
n = 0length = 5return = "00000"The first stage starts with the all-zero five-digit plate.
Example 2
n = 99999length = 5return = "99999"This is the last all-digit plate.
Example 3
n = 100000length = 5return = "A0000"After 100000 digit-only plates, the one-letter stage begins.
Example 4
n = 360length = 2return = "AA"Length two has 100 digit plates and 260 one-letter plates before the all-letter stage.
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.