We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
intnext_permutation(intn,char**s){intk=-1;for(inti=0;i<n-1;i++){if(strcmp(s[i],s[i+1])<0)k=i;}// printf("k = %d",k);if(k==-1)return0;intl=-1;for(inti=k+1;i<n;i++){if(strcmp(s[k],s[i])<0)l=i;}// printf("\nl = %d",l);if(l!=-1){char*temp=s[k];s[k]=s[l];s[l]=temp;}//Reverse the sequence from a[k + 1] up to and including the final element a[n].intstart=k+1;intend=n-1;while(start<end){char*temp=s[start];s[start]=s[end];s[end]=temp;start++;end--;}return1;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Permutations of Strings
You are viewing a single comment's thread. Return to all comments →
Refer here : https://en.wikipedia.org/wiki/Permutation#Generation_in_lexicographic_order