Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: A grid of 5×5 cells has 'X' blocked cells at (0,2), (1,2), (2,2), (3,2) (row, column, 0-indexed); the rest are open. Cells connect up, down, left and right. What is the size of the largest connected group of open cells?

  1. A. 10
  2. B. 25
  3. C. 20
  4. D. 21

Correct answer: D. 21

Column 2 is blocked only in rows 0-3, so the open cell (4, 2) joins the left and right halves: 25 − 4 = 21 open cells form one group. Assuming the wall cuts the grid in two gives 10, ignoring the walls gives 25, and dropping the bridge cell gives 20.

More Coding Interview Problems questions

Exams that ask this topic