Given an integer, find the next biggest integer whose digits are in increasing order. Example: Input: 118 Output: 123 Input: 127 Output: 234 Input: 987 Output: 1234 Desing question: Design a parking space to park a car.
Anonymous
Below is the Function for solving the same : int numberOfDigitInK(int k) { int count = 0; while (k % 10 != 0) { k = k / 10; count++; } return count; } int findNextHigherDigit(int k) { int count = this.numberOfDigitInK(k); int higherNumber = 0; int firstDigit = k / (int) Math.pow(10, count - 1); int flag = count; int incrementer = 0; int lastResort = 0; int one = 1; while (flag + 1 > 0) { lastResort += one * Math.pow(10, flag); flag--; one++; } flag = count; while (flag > 0) { higherNumber += firstDigit * Math.pow(10, flag - 1); flag--; firstDigit++; incrementer += 1 * Math.pow(10, flag); } while (higherNumber k) { return higherNumber; } higherNumber += incrementer; } return lastResort; } return lastResort; }
Check out your Company Bowl for anonymous work chats.