Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT

Using the same kind of binary matrix, [[1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0]], what is the area of the largest SQUARE made only of 1s?

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

Correct answer: D. 4

Let d[i][j] be the side of the largest all-ones square whose bottom-right corner is (i, j): d = 1 + min(up, left, diagonal) when the cell is 1. The answer is the maximum d squared.

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

Exams that ask this topic