given two numbers one with more digits is the greater number. if the number of digits in two given numbers is the same that number is Greater which has a greater left most digit. if this digit also happens to be the same we look at the next digit on the left and so on
Answers
Answered by
2
Answer:
☟︎︎︎
Step-by-step explanation:
Find next greater number with same set of digits
Given a number n, find the smallest number that has same set of digits as n and is greater than n. If n is the greatest possible number with its set of digits, then print “not possible”.
Examples:
For simplicity of implementation, we have considered input number as a string.
Input: n = "218765"
Output: "251678"
Input: n = "1234"
Output: "1243"
Input: n = "4321"
Output: "Not Possible"
Input: n = "534976"
Output: "536479
Similar questions