Data Structures & AlgorithmsVery hardICPC regional · CAT · MBA placement
Problem: The number of ways to choose 3 vertices from a graph's vertex set of size n = 12 such that no two chosen vertices are adjacent in a cycle C12 (vertex i is adjacent to i±1 mod 12). Compute the count.
- A. 220
- B. 336
- C. 112
- D. 120
Correct answer: C. 112
Independent k-sets of a cycle number n/(n − k) · C(n − k, k) = 12/9 · C(9, 3) = 112. A path (no wrap-around) gives C(10, 3) = 120, ignoring adjacency gives C(12, 3) = 220, and forgetting to divide 12 · C(8, 2) by k = 3 gives 336.
More Coding Interview Problems questions
- Problem: A stream of 12 numbers 5, 1, 4, 4, 2, 5, 3, 1, 2, 3, 3, 4 arrives. How many distinct values appear at least twice in the stream?
- Problem: Start with x = 5. Repeat this rule: if x is odd, set x = x + 3; if x is even, set x = 2x − 1. Count how many times the rule is…
- Problem: Starting from 0 on a number line, a frog jumps +4, then −1, then +4, then −1 and so on, alternating, for 25 jumps in total. It…
- Problem: Count the vertices of the tree with edges 0–1, 0–2, 1–3, 1–4, 2–5, 5–6, 5–7 whose removal leaves every remaining connected…
- Problem: Vertices 1–6 have these directed prerequisites: 1→4, 2→4, 2→5, 3→5, 4→6, 5→6. Among all valid topological orders, the…
- Problem: A graph on vertices 0–7 has edges 0-1, 1-2, 2-0, 3-4, 4-5, 5-6, 6-3, 6-7. The edges are removed one at a time in this order: 2-0…