Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: In a directed graph on vertices 0–3, the arcs are 0→1, 1→2, 2→0, 2→3. The vertex 3 has no outgoing arcs. How many vertices can reach vertex 3?
- A. 4
- B. 2
- C. 3
- D. 5
Correct answer: C. 3
Reverse search from the target: any vertex with an arc into a vertex that can reach 3 can also reach it. Here 2 reaches 3 directly, then 1 and 0 reach 2, so all three other vertices qualify.
More Coding Interview Problems questions
- Problem: A rooted tree has root 1 and children 1: [2, 3, 4], 3: [5], 4: [6, 7]. The number of nodes on the longest root-to-leaf path…
- Problem: The string "abcdcba" is checked for palindromic substrings with an odd length of at least 5. How many such substrings are there?
- Problem: What is the number of distinct strings of length 4 over the alphabet {a, b} containing at least one 'a' and at least one 'b'?
- Problem: The string "aabbccddee" is compressed by keeping each character once for every run of length at least two, followed by the count…
- Problem: Calculate the number of ordered pairs (x, y) of integers with 1 ≤ x, y ≤ 20 for which x² + y² is divisible by 5.
- Problem: A lattice path goes from (0,0) to (3,3) using steps right (1,0) and up (0,1), and it must never go above the diagonal (that is…