Next Number with Disjoint Digits
Updated
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.
More ElevenLabs interview questions
Similar questions at other companies
- Unique Digit Permutations Without Leading ZeroMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Signed Digit Partitions Reaching a TargetMeta · PHONE SCREENMeta interview questions
- Knights, Knaves and Their StatementsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Perfect Squares Matching a PatternNielsen · OA
- Simplify a Quadratic ExpressionOpenAI · OAOpenAI interview questions
- String Permutations in Custom Character OrderWex · OA · PHONE SCREEN
- Vowel Substring GameAkuna Capital · OAAkuna Capital interview questions
- Minimum Anagram PeriodVisa · OAVisa interview questions
- Return Exact Cash Register ChangeBank of America · OABank of America interview questions
- Maximum Equal Parts for PrefixesAmazon · OA