Data Structures & AlgorithmsHardICPC regional · CAT · MBA placement
Problem: Place 4 non-attacking rooks on a 4×4 board (no two share a row or column) such that none is on a forbidden cell. Forbidden cells are (0,0), (1,1), (2,2), (3,3), (0,1). How many valid placements exist?
- A. 9
- B. 24
- C. 11
- D. 6
Correct answer: D. 6
Placements are permutations σ with σ(i) ≠ i and σ(0) ≠ 1; of the 9 derangements of 4, three send 0 to 1, leaving 6. Ignoring the (0,1) restriction gives the 9 derangements, ignoring all restrictions gives 4! = 24, and 11 merely counts the allowed cells.
More Coding Interview Problems questions
- Problem: In a grid of 0s and 1s, a connected region is a group of 1-cells that are connected when moving to 8 neighbours (up, down, left…
- Problem: A rooted tree is given by parent array p = [-1, 0, 0, 1, 1, 2, 5, 5, 3] for nodes 0–8 (node 0 is the root). How many nodes are at…
- Problem: A max-heap starts with the values 9, 8, 6, 5, 4, 3, 1 (inserted in that order). Then three times in succession: pop the maximum…
- Problem: The string "abcbaxyzzyxq" is given. What is the minimum number of characters that must be deleted so the remaining string is a…
- Problem: A string is formed by writing the letters of "kayak" then "level" then "rotor". How many substrings of length 5 of…
- Problem: Starting from the string "00000" of five zeros, operations flip a substring: each operation chooses positions l ≤ r and flips…