Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 B

Problem: In a grid of 0s and 1s, a connected region is a group of 1-cells that are connected when moving to 8 neighbours (up, down, left, right and the four diagonals). Count the regions in: 11000 11011 00100 01100 10001

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

Correct answer: A. 2

With 8-connectivity, diagonal neighbours merge regions that 4-connectivity would split. Counting with only horizontal and vertical moves gives a larger number.

More Coding Interview Problems questions

Exams that ask this topic