Data Structures & AlgorithmsHardTCS NQT · Product Company SDE

Problem: A grid of 3×3 cells is numbered 1 to 9 row by row. Starting at 1 (top-left), the robot moves right or down. The number of paths that visit the centre cell (value 5) is what value?

  1. A. 5
  2. B. 3
  3. C. 6
  4. D. 4

Correct answer: D. 4

There are 6 monotone paths from top-left to bottom-right. Two reach the centre from the top-left and two leave it toward the bottom-right, so 2 × 2 = 4 paths pass through the centre.

More Coding Interview Problems questions

Exams that ask this topic