Data Structures & AlgorithmsHardICPC regional · GATE CS
Problem: Compute the number of paths of length exactly 3 from vertex 0 to vertex 2 in the undirected graph with edges 0-1, 1-2, 0-2, 2-3 (walks may repeat vertices and edges).
- A. 5
- B. 3
- C. 4
- D. 6
Correct answer: C. 4
Walk counting by repeated propagation over the adjacency lists gives every walk of length three that ends at vertex 2. Counting only simple paths would exclude walks that revisit vertices.
More Coding Interview Problems questions
- Problem: The sum of all positive integers up to 500 that are divisible by 3 but not by 5 is what value?
- Problem: How many distinct values does the expression (a² + b²) mod 5 take as a and b range over 0 ≤ a, b ≤ 4?
- Problem: In the array [9, 4, 7, 1, 8, 2], the element 7 is at index 2. Find the number of elements to the right of index 2 that are…
- Problem: The string "abacaba" is processed: each character is replaced by the number of times it has appeared so far (including this…
- Problem: Two heaps are used to track the minimum and maximum of a sliding window of size 3 over [4, 8, 1, 9, 3, 7]. How many windows have…
- Problem: The product of the digits of 2^10 · 3^4 is computed (in decimal). What is that product?