Next Number with Disjoint Digits
Problem statement
Given a positive 32-bit integer n, find the smallest integer strictly greater than n whose decimal digits do not occur anywhere in the decimal representation of n.
Repeated digits are allowed in the result. Return -1 when no qualifying integer fits in a signed 32-bit integer.
Function
nextDisjointDigitNumber(n: int) → intExamples
Example 1
n = 654321return = 700000Digits 0, 7, 8, and 9 are allowed. The smallest allowed six-digit number above n is 700000.
Example 2
n = 98return = 100The result cannot contain 9 or 8; 100 is the first greater number using only allowed digits.
Constraints
1 <= n < 2^31 - 1.- The result, when it exists, is at most
2^31 - 1. - Leading zeroes are not part of a decimal representation.