Data Structures & AlgorithmsHardProduct Company SDE · ICPC regional
Problem: A directed graph has arcs 0→1 (0), 1→2 (3), 0→2 (5), 2→3 (0), 1→3 (7), 3→4 (2), 2→4 (4), 4→5 (1), 0→5 (9). Arc weights may be zero but there are no negative weights. What is the shortest distance from vertex 0 to vertex 5?
- A. 9
- B. 6
- C. 8
- D. 10
Correct answer: B. 6
The cheapest route is 0→1→2→3→4→5 with cost 0 + 3 + 0 + 2 + 1 = 6. The direct arc costs 9 (fewest arcs, not least weight), 0→2→3→4→5 costs 8, and 0→1→3→4→5 costs 10.
More Coding Interview Problems questions
- Problem: A tree on 6 nodes has edges 1-2, 1-3, 1-4, 4-5, 4-6. How many pairs of edges share a common endpoint (that is, unordered pairs of…
- Problem: The string "cbaebabacd" is scanned with windows of length 3. How many windows are anagrams of "abc" (same letters, same counts…
- Problem: The string "aaaaa" is split into non-overlapping occurrences of "aa" from left to right (greedily taking each match). How many…
- Problem: In the string "aabcbcdbca", what is the length of the shortest substring that contains exactly 3 distinct letters?
- Problem: What is the length of the longest palindromic substring of "abcbxa" that can be made a palindrome after deleting at most one…
- Problem: How many sequences made of the numbers 1 and 2 sum to 8, where no two 2s are adjacent (order matters)?