Accenture Coding Question | Next Greater Number | CodeWindow

Next Greater Number

Write a number ‘N’ (containing at most 10,000 digits), find the next grater number having the same digits. It is guaranteed that there exists a next greater number having the same digits as N.

Input specification:
Input1: The length of the string ‘N’.
Input2: The number ‘N’ in the form of a string.

Output Specification:
Return the next greater number having the same digits as ‘N’ in the form of a string.

Example 1:
Input 1: 3
Input 2: 182

Output: 218
Explanation:
The next greater number after 182 is 218 using {1,8,2}

Example 2:
Input 1: 4
Input 2: 2345

Output: 2354
Explanation:
The next greater number after 2345 is 2345 using {2,3,4,5}

Solution in Python 3:

Solution in C++ :

Solution in JAVA :

Output:

Recent Posts
Pages