Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: A directed graph on vertices 0–4 has arcs 0→1 (2), 0→2 (6), 1→2 (3), 1→3 (9), 2→3 (1), 3→4 (2), 2→4 (8). What is the length of the shortest path from 0 to 4?
- A. 8
- B. 9
- C. 13
- D. 14
Correct answer: A. 8
0→1→2→3→4 costs 2 + 3 + 1 + 2 = 8. Taking the 6-arc first (0→2→3→4) costs 9, 0→1→3→4 and 0→1→2→4 both cost 13, and 0→2→4 costs 14.
More Coding Interview Problems questions
- Problem: Vertices 1–6 of an undirected graph have edges 1-2, 2-3, 4-5, 5-6, 6-4 and 3-1. How many edges are NOT part of any cycle?
- Problem: A rooted tree (root 1) has children 1: [2, 3], 2: [4], 3: [5, 6], 5: [7]. What is the number of nodes at depth 2 (root at depth 0)?
- Problem: The string "mississippi" contains repeated substrings. What is the length of the longest substring that appears at least twice…
- Problem: For the string "abcabcdab", how many substrings of length 3 occur exactly once?
- Problem: How many integers from 1 to 500 are NOT perfect squares and NOT perfect cubes?
- Problem: The dynamic array doubles its capacity whenever it is full, starting from capacity 1. After inserting 9 elements one by one, how…