Data Structures & AlgorithmsVery hardICPC regional · GATE CS
How many permutations p of 1, 2, ..., 6 satisfy p[i] ≤ i + 1 for every position i (1-based)?
- A. 17
- B. 120
- C. 1
- D. 64
Correct answer: C. 1
Count from the last position: position i can take any of the values not used by later positions, so the choices multiply as 1, 2, 2, 2, ..., giving 2^(n−1) permutations. The count 2ⁿ overstates it by a factor of two.
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
- How many distinct arrangements of the letters of "aabbcc" have no two adjacent letters equal?
- Count monotone lattice paths from (0, 0) to (3, 3) that move one step right (x+1) or up (y+1) and never touch a point (i, i) with 0 < i <…
- How many arrays of length 4 with entries from {0, 1, 2} have an EVEN total sum?
- Pick one number from each of the lists [4, 9, 2], [7, 3, 8] and [5, 6, 1]. The three picks must sum to at most 14. What is the largest…
- Among the windows of exactly 3 consecutive elements of [4, 2, 4, 1, 3, 5, 2, 6] whose 3 values are all different, what is the largest…
- Consider only the elements at even 0-based indices of [5, 2, 8, 1, 7, 3, 9, 4] (that is, 5, 8, 7, 9). How many inversions (pairs i < j of…