Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
How many permutations of (0, 1, 2, 3) have exactly one position i with p[i] = i?
- A. 11
- B. 8
- C. 6
- D. 9
Correct answer: B. 8
Choose the fixed point (4 ways), then count derangements of the other three elements, which is 2. Total 4 times 2 = 8. Counting derangements of all four elements gives a different number.
More Coding Interview Problems questions
- Arrays A = [2, 5, 3, 7] and B = [4, 6, 1, 9]. How many pairs (x from A, y from B) satisfy 10 <= x y <= 40?
- Trains arrive at 100, 140, 150, 180, 200 and depart at 120, 160, 190, 210, 230 (times are not paired). A platform holds one train at a…
- Array [1, 2, 1, 3, 2, 2]. How many contiguous subarrays contain exactly two distinct values?
- Sorted arrays [2, 6, 9, 14] and [4, 7, 11, 15] are merged into one list. How many elements of the merged list lie strictly between 5 and 12?
- Choose a from {6, 9, 12} and b from {3, 5, 10}. What is the largest possible value of a XOR b?
- Tasks AAABBC must be scheduled one per time unit; two identical tasks need at least 2 idle-free units between them (cooldown k = 2, i.e…