Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE
Problem: Dijkstra's algorithm in an undirected graph with edges 0-1 (2), 1-2 (2), 0-2 (5), 2-3 (1), 1-3 (6). How many vertices have a shortest distance from vertex 0 strictly greater than 3?
- A. 3
- B. 1
- C. 4
- D. 2
Correct answer: D. 2
Run Dijkstra fully, then count distances above 3. Using only direct edges from 0 gives larger distances for some vertices and the wrong count.
More Coding Interview Problems questions
- Problem: The string "xyyxzzyx" is examined for palindromic substrings of length 4 or more. How many such palindromic substrings are there…
- Problem: A binary string is "good" if it has no two consecutive zeros. How many good strings of length 7 begin with 1 and end with 1?
- Problem: A process list is [3, 7, 2, 9] with priorities; the CPU always runs the largest value next and runs it for its full value, then…
- Problem: How many subarrays of [2, 4, 6, 1, 3, 5] have all elements even or all elements odd?
- Problem: The number 9 is written in base 3 as 100. How many numbers from 1 to 100 have a base-3 representation with no digit 2?
- Problem: On a line of cells 0–9, a token starts at cell 0. Each second it moves right by 2 if the cell is even, and left by 1 if the cell…