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?
- A. 23
- B. 21
- C. 22
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- List all distinct permutations of the multiset of letters in "aabc" in alphabetical order. What is the 5th string in this list?
- What is the length of the longest substring of "aabbcabccbba" in which every letter occurs an EVEN number of times (0 counts as even)?
- How many unordered pairs of positions in [2, 8, 9, 18, 4, 6, 12] have a product that is a perfect square?
- For each window of 3 consecutive elements of [1, 2, 1, 3, 2, 1, 4], count the number of DISTINCT values in it. What is the sum of these…
- Repeatedly delete any adjacent pair of letters that are 'a' and 'b' (in either order) from "abbaabbbaab" until none remains. What is the…
- Cards with values [4, 1, 7, 3, 9, 2, 5] lie in a row. In each of 3 moves you take the card at the LEFT end or the RIGHT end. What is the…