Data Structures & AlgorithmsVery hardGATE CS
How many permutations of {1, 2, …, 8} have exactly two fixed points (positions i with π(i) = i)?
- A. 10080
- B. 1232
- C. 7420
- D. 22253
Correct answer: C. 7420
Choose the 2 fixed positions (C(8,2)=28) and arrange the other 6 as a derangement (D6=265): 7420. Using D5 or counting all 6! arrangements ignores that the other six must have no fixed point.
More Coding Interview Problems questions
- How many integers n with 1 ≤ n ≤ 999 have digit sum exactly 12 and contain no digit 0 (in their usual decimal form, without leading zeros)?
- Find the length of the longest common subsequence of X = "AGGTABQXZRYWM" and Y = "GXTXAYBZQMWRY".
- What is the minimum number of characters that must be inserted anywhere in "CBAABDCABBDAC" to make it a palindrome?
- Matrices A1…A7 have dimensions 5×10, 10×3, 3×12, 12×5, 5×50, 50×6, 6×8. What is the minimum number of scalar multiplications needed to…
- A 2 × 11 board is tiled completely using 1 × 2 dominoes (placed either way) and 2 × 2 squares. How many different tilings are there?
- The 3 × 3 grid graph (9 vertices, 12 edges) has a diagonal edge added between its top-left corner and its centre vertex, giving a 13-edge…