Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: Consider the undirected graph with edges 0-1, 1-2, 2-0, 2-3, 3-4 and 4-5, 5-3. A DFS from vertex 0 (visiting neighbours in increasing order) records each vertex when first entered. In what order are the vertices entered? Report the 5th vertex entered (1-based).
- A. 5
- B. 4
- C. 3
- D. 6
Correct answer: B. 4
Recursive DFS enters a vertex, then immediately explores its smallest unvisited neighbour. The order is 0, 1, 2, 3, 4, 5, so the fifth vertex entered is 4.
More Coding Interview Problems questions
- Problem: Counting sort is applied to [3, 1, 2, 3, 0, 1] with keys in the range 0 to 3. After counting occurrences and computing prefix…
- Problem: The string "aaabbcccc" has its runs counted. What is the length of the longest run of identical characters?
- Problem: How many integers from 1 to 300 are divisible by 4 or 6 but not by 12?
- Problem: A list of numbers is [10, 4, 9, 7, 5, 12]. A "peak" is an element strictly greater than both of its neighbours (end elements have…
- Problem: The string "racecarxyz" is examined for palindromic substrings of length at least 5. How many such palindromic substrings are…
- Problem: The number of ways to arrange the letters of "LEVEL" so that the two E's are not adjacent is what value?