Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: Consider the directed graph with arcs 1→2, 2→3, 3→4, 4→2, 1→5. Starting from 1, how many distinct vertices are reachable (including 1)?
- A. 6
- B. 4
- C. 5
- D. 7
Correct answer: C. 5
The reachable set from 1 is {1, 2, 3, 4, 5}, and the cycle 2→3→4→2 does not add any new vertices beyond these.
More Coding Interview Problems questions
- Problem: In the array [9, 2, 6, 4, 7, 1], what is the number of elements that are smaller than every element to their left (strict left…
- Problem: The number 2^10 − 1 has how many distinct prime factors?
- Problem: A text buffer contains "hello world". Each space is replaced by the three characters "%20" (URL-style encoding). What is the…
- Problem: The bitwise AND of all integers from 12 to 15 inclusive is computed. What is the result?
- Problem: A row of 5 seats is filled by 3 distinct people, leaving 2 seats empty. How many arrangements are possible if the empty seats…
- Problem: The sum of the squares of the odd numbers from 1 to 19 is what value?