Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional

Among all distinct permutations of the letters of "dbca" sorted alphabetically, what is the 1-based position of "dbca" itself?

  1. A. 23
  2. B. 21
  3. C. 22
  4. D. 25

Correct answer: C. 22

For each position, count the unused letters smaller than the current letter and multiply by the number of arrangements of the rest, using factorials. The rank is the sum plus one; forgetting the +1 or the multiplicities gives an off-by-one or a wrong total.

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

Exams that ask this topic