FastPrepMinimum Unique Card Suffix Length

Minimum Unique Card Suffix Length

Bloomberg LP logoBloomberg LP● MediumNEW GRADONSITE INTERVIEW
Learn

Problem statement

Each distinct nonnegative integer in cardNumbers is a bank-card number. Return the smallest positive integer k such that the last k decimal digits of every card number are unique across the array.

The last k digits of a number are its remainder modulo 10^k. If a number has fewer than k digits, its suffix value is the entire number. Because all card numbers are distinct and fit in at most 16 decimal digits, a valid k always exists.

Function

minimumUniqueSuffixLength(cardNumbers: long[]) → int

Examples

Example 1

cardNumbers = [1111111111111234,2222222222221224,3333333333331235]return = 2

One digit gives 4, 4, 5, so the first two cards collide. Two digits give 34, 24, 35, which are all unique.

Example 2

cardNumbers = [10,20,30]return = 2

All one-digit suffixes are 0. The two-digit suffixes are 10, 20, 30.

Example 3

cardNumbers = [101,202,303]return = 1

The one-digit suffixes 1, 2, 3 are already distinct.

Constraints

  • 1 <= cardNumbers.length <= 100000.
  • 0 <= cardNumbers[i] <= 9000000000000000.
  • All values in cardNumbers are distinct.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int minimumUniqueSuffixLength(long[] cardNumbers) {
    // Write your code here.
}
cardNumbers[1111111111111234,2222222222221224,3333333333331235]
expected2
Checking account…