Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: A path graph has vertices 1–6 with edges between consecutive vertices. How many pairs of vertices are at distance exactly 2?
- A. 5
- B. 4
- C. 3
- D. 6
Correct answer: B. 4
On a path, two vertices are at distance two exactly when their labels differ by two, which gives four pairs for six vertices.
More Coding Interview Problems questions
- 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…
- 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…