Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: In the grid of 0s and 1s below, count the number of 2×2 all-ones squares. 1110 1111 0111 1111

  1. A. 7
  2. B. 21
  3. C. 6
  4. D. 9

Correct answer: C. 6

Check each of the 9 top-left positions: 6 of the 2 × 2 blocks are all ones. Also counting the single 3 × 3 all-ones block gives 7, counting all-ones squares of every size gives 21, and 9 counts every 2 × 2 position regardless of content.

More Coding Interview Problems questions

Exams that ask this topic