Data Structures & AlgorithmsHardICPC regional · GATE CS top band

A 6 × 6 grid (rows top to bottom, '#' = land, '.' = water): .#.... / ..#.#. / ##...# / #...#. / ##...# / ..##.#. Land cells form an island when they are connected through sides only (up, down, left, right; diagonal contact does not connect). What is the number of cells in the largest island?

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

Correct answer: D. 5

The largest side-connected island has 5 cells; allowing diagonal contact would merge pieces and report 9, which is the common mistake.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic