Data Structures & AlgorithmsModerateCodeforces Div 2 · ICPC regional

A 6 × 6 grid (rows top to bottom, '#' = filled, '.' = empty): ...... / ..#... / .#.### / ....#. / #...## / .#..#.. Two filled cells belong to the same group if they are adjacent horizontally, vertically or diagonally. How many groups are there?

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

Correct answer: C. 2

Counting groups with 8-directional adjacency gives 2; using only 4 directions merges diagonal pairs and gives 5, so the neighbourhood rule decides the answer.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic