Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
The 4-cycle graph 0-1-2-3-0 (undirected, so both directions of every edge exist) is given as an adjacency matrix. How many ordered sequences (v0, v1, v2, v3) use all four vertices exactly once with consecutive vertices adjacent?
- A. 4
- B. 24
- C. 8
- D. 16
Correct answer: C. 8
An ordered sequence is a directed Hamiltonian path, so a path and its reversal count separately. The mask DP counts each ordering; halving it gives undirected paths, which is the trap. Unrestricted orderings of 4 vertices number 24, but adjacency removes most of them.
More Coding Interview Problems questions
- Worker i has the cost C[i][j] of doing job j, with C = [[9,2,7,8],[6,4,3,7],[5,8,1,8],[7,6,9,4]]. Each worker takes exactly one distinct…
- How many subsets of {1, 2, 3, ..., 12} have XOR equal to 0? The empty subset counts, because its XOR is 0.
- How many binary strings of length 10 contain no two adjacent 1s?
- In how many ways can a 3 x 4 grid be covered completely by non-overlapping 1 x 2 dominoes (each domino covers two adjacent cells, in…
- The universe {0, ..., 5} must be covered by a union of chosen sets from {0,1,2}, {2,3}, {3,4,5}, {0,4}, {1,5}. What is the minimum number…
- How many subsets (including the empty subset) of {1, 2, ..., 10} have a sum divisible by 3?