Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Problem 604. Next lexicographic - permutation

Created by Muthu Annamalai

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 )
         cycle = cycle+1;

For fun, you could generate all the n! permutations of a, unique n-letter string.

Problem Group

Solution Statistics

23 correct solutions 23 incorrect solutions
Last solution submitted on Dec 13, 2014

Solution Comments