FastPrepNth Fixed-Format License Plate

Nth Fixed-Format License Plate

Google logoGoogle● MediumNEW GRADONSITE INTERVIEW
Learn

Problem statement

A license plate contains exactly letterCount uppercase English letters followed by exactly digitCount decimal digits. For example, three letters and three digits produce plates such as AAA000.

Sort every valid plate lexicographically. Given a one-indexed position n, return the plate at that position.

Function

nthFixedFormatLicensePlate(letterCount: int, digitCount: int, n: long) → String

Examples

Example 1

letterCount = 3digitCount = 3n = 1return = "AAA000"

AAA000 is the first plate.

Example 2

letterCount = 3digitCount = 3n = 1001return = "AAB000"

AAA000 through AAA999 occupy the first 1000 positions, so AAB000 is next.

Example 3

letterCount = 1digitCount = 2n = 2600return = "Z99"

This is the final plate for one letter and two digits.

Constraints

  • 1 <= letterCount, digitCount <= 6.
  • 1 <= n <= 26^letterCount * 10^digitCount.

More Google problems

See Google hiring insights
public String nthFixedFormatLicensePlate(int letterCount, int digitCount, long n) {
    // write your code here
}
letterCount3
digitCount3
n1
expected"AAA000"
Checking account…