Data Structures & AlgorithmsVery hardICPC regional · Product Company SDE
Problem: On the undirected graph with edges 0-1 (4), 0-2 (1), 2-1 (2), 1-3 (5), 2-3 (9), 3-4 (3), find the minimum number of edges used by any path of minimum total weight from vertex 0 to vertex 4.
- A. 5
- B. 3
- C. 6
- D. 4
Correct answer: D. 4
Lexicographic Dijkstra on (weight, edges) pairs picks the fewest edges among minimum-weight paths. Ignoring the tie-break can return a longer path with the same weight.
More Coding Interview Problems questions
- Problem: The rooted tree (root 1) has children 1: [2, 3], 2: [4, 5], 3: [6], 4: [7], 6: [8]. How many nodes have a depth divisible by 3…
- Problem: In the string "abcbaxyzzyx", count the palindromic substrings of length exactly 5.
- Problem: How many adjacent positions i (0 ≤ i < n−1) of "abbaabab" form the pair "ab" or the pair "ba"?
- Problem: How many indices i satisfy s[i] = s[i+2] in the string "abcabcab" (0 ≤ i ≤ n−3)?
- Problem: How many distinct strings are obtained from "abab" by cyclic rotations (including the rotation by 0)?
- Problem: What is the minimum number of character replacements needed to make "abcdba" a palindrome?