Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: A grid has 4 rows and 4 columns. Cell (r, c) holds value (r·c) mod 3. Starting at (0,0), a path moves right or down to (3,3). What is the minimum possible sum of values along such a path (start and end included)?

  1. A. 0
  2. B. 1
  3. C. 2
  4. D. 3

Correct answer: A. 0

Min-path DP over the grid: each cell takes the smaller of its top and left predecessors plus its own value. Greedy choice of the smaller neighbour at each step can end up with a larger total.

More Coding Interview Problems questions

Exams that ask this topic