Data Structures & AlgorithmsHardICPC regional · Product Company SDE

Problem: What is the lexicographically next permutation of the string "bcdea" (the next arrangement in dictionary order using the letters of that string)?

  1. A. bcdae
  2. B. eabcd
  3. C. bcead
  4. D. bcaed

Correct answer: C. bcead

Find the rightmost ascent, swap it with the smallest larger suffix letter, then reverse the suffix. Simply sorting the suffix without the swap gives a different string.

More Coding Interview Problems questions

Exams that ask this topic