Data Structures & AlgorithmsHardICPC regional · Product Company SDE
Problem: A directed graph on 6 vertices (0–5) has arcs 0→1, 1→2, 0→3, 3→2, 2→4. How many ordered pairs (u, v) with u ≠ v have v unreachable from u?
- A. 25
- B. 21
- C. 9
- D. 10
Correct answer: B. 21
Reachable pairs: 0→{1,2,3,4}, 1→{2,4}, 3→{2,4}, 2→{4}: 9 of the 30 ordered pairs, so 21 are unreachable. Counting only non-arcs gives 25, 9 is the reachable count, and treating arcs as undirected gives 10.
More Coding Interview Problems questions
- Problem: An undirected graph has 8 vertices and 11 edges with exactly 2 connected components. What is the minimum number of edges that…
- Problem: For the path graph P5 on vertices 1–5 (edges 1-2, 2-3, 3-4, 4-5), what is the sum of the distances over all unordered pairs of…
- Problem: The string "abcdabcd" is examined for windows of length 4 with all four characters distinct. How many such windows are there?
- Problem: What is the minimum number of characters to delete from "programming" so that all remaining characters are distinct (keep one…
- Problem: Compute the longest palindromic prefix of "abacabacaba" (the longest prefix that reads the same backwards). What is its length?
- Problem: What is the length of the longest common substring (contiguous) of "abcdxyz" and "xyzabcd"?