Data Structures & AlgorithmsVery hardCodeforces Div2 D · TCS NQT

List all distinct permutations of the multiset of letters in "aabc" in alphabetical order. What is the 5th string in this list?

  1. A. abca
  2. B. acba
  3. C. abac
  4. D. acab

Correct answer: D. acab

Count arrangements with a given prefix using multinomial coefficients (the repeated letter divides the count by 2!), then descend letter by letter. Treating the letters as distinct overcounts every arrangement with a repeated 'a'.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic