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?

  1. A. 5
  2. B. 4
  3. C. 3
  4. 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

Exams that ask this topic