Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE
Problem: Consider the directed graph with arcs 1→2, 2→3, 3→1, 3→4, 4→2, 4→5. How many vertices can reach vertex 5?
- A. 4
- B. 5
- C. 3
- D. 6
Correct answer: A. 4
Reverse reachability: start from vertex 5 and repeatedly add any vertex with an arc into the set. Counting only direct predecessors of 5 would miss vertices that reach it through a chain.
More Coding Interview Problems questions
- Problem: A string of length 6 is formed using letters only from {a, b}, containing no substring "aa" or "bb". How many such strings are…
- Problem: Compute the number of paths of length exactly 3 from vertex 0 to vertex 2 in the undirected graph with edges 0-1, 1-2, 0-2, 2-3…
- Problem: The sum of all positive integers up to 500 that are divisible by 3 but not by 5 is what value?
- Problem: How many distinct values does the expression (a² + b²) mod 5 take as a and b range over 0 ≤ a, b ≤ 4?
- Problem: In the array [9, 4, 7, 1, 8, 2], the element 7 is at index 2. Find the number of elements to the right of index 2 that are…
- Problem: The string "abacaba" is processed: each character is replaced by the number of times it has appeared so far (including this…