Data Structures & AlgorithmsHardTCS NQT · Accenture

The 0/1 grid [[1,1,0],[0,1,0],[1,0,1]] is given. Two 1-cells belong to the same island if they are adjacent horizontally or vertically. How many islands are there?

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

Correct answer: D. 3

The cells (0,0), (0,1) and (1,1) form one island, (2,0) is another, and (2,2) is a third. Diagonal neighbours are not connected.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic