Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: A directed graph on vertices 0–5 has arcs 0→1, 1→2, 2→0, 2→3, 3→4, 4→3, 4→5, 5→1. How many vertices have in-degree equal to out-degree?
- A. 3
- B. 1
- C. 2
- D. 4
Correct answer: C. 2
Tally in-degrees and out-degrees separately from the arc list, then compare per vertex. Comparing total degree (sum of both) with the counts gives a different test.
More Coding Interview Problems questions
- Problem: On the undirected graph with edges 0-1 (4), 0-2 (1), 2-1 (2), 1-3 (5), 2-3 (9), 3-4 (3), find the minimum number of edges used by…
- Problem: The rooted tree (root 1) has children 1: [2, 3], 2: [4, 5], 3: [6], 4: [7], 6: [8]. How many nodes have a depth divisible by 3…
- Problem: In the string "abcbaxyzzyx", count the palindromic substrings of length exactly 5.
- Problem: How many adjacent positions i (0 ≤ i < n−1) of "abbaabab" form the pair "ab" or the pair "ba"?
- Problem: How many indices i satisfy s[i] = s[i+2] in the string "abcabcab" (0 ≤ i ≤ n−3)?
- Problem: How many distinct strings are obtained from "abab" by cyclic rotations (including the rotation by 0)?