Find the next greater number
Given a number find the smallest number that is greater than n, and has same number of digits as n. Input: n = "218765" Output: "251678" Input: n = "1234" Output: "1243" Input: n = "4321" Output: "Not Possible" Input: n = "534976" Output: "536479" Steps: Consider 3,2,8,4,1 1. Start from right and find the digit that is smaller than its next digit. 3, 2 < 8 >4 >1 2. Swap that digit with its next higher number in the right. 3, 2 , 8, 4 , 1 (next higher digit of 2 is 4) 3, 4 ,8, 2 ,1 3. Reverse the digits to the right of that digit (4). 3,4,1,2,8 Code: import java.util.*; public class Solution { static void findNextGreater(int[] a){ int n = a.length; int position = -1; for(int i=n-1; i>0; i--){ ...