1.

Given the following permutation of a,b,c,d,e,f,g,h,i,j, what is the previous permutation in lexicographic (dictionary) order? Write your answer without any blank spaces between letters.fjadchbegi

Answer»

Answer:

First of all Find the HIGHEST index as i such as s[i] < s[i+1]. If suppose an index exists, the permutation will has last permutation.

Again find the highest index like j > i such that s[j] > s[i]. Such that j must EXIST, SINCE i+1 is such an index.

Swap s[i] with s[j].

Reverse all of the elements in order after index i till the last element.

Explanation:



Discussion

No Comment Found