Next lexicographic - permutation - MATLAB Cody - MATLAB Central

Problem 604. Next lexicographic - permutation

Difficulty:Rate
Find next lexicographic - permutation (permutations as it would occur in a dictionary order).
E.g: nextP('ABCD') = ABDC
If you can generate the next permutation, then you can also generate a 'cycle' of all permutations using a construct like,
cycle = +1;
curr = start;
while ( true )
curr = nextP(curr);
if ( curr == start )
break;
end
cycle = cycle+1;
end
For fun, you could generate all the n! permutations of a, unique n-letter string.

Solution Stats

42.95% Correct | 57.05% Incorrect
Last Solution submitted on Jul 21, 2023

Problem Comments

Solution Comments

Show comments

Group

Combinatorics I Image
Combinatorics I
  • 15 Problems
  • 28 Finishers

Problem Recent Solvers49

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Go to top of page