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?
- A. abca
- B. acba
- C. abac
- 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'.
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
- 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…
- How many ordered sequences of positive integers, each at most 3 and with at least two terms, sum to 6?