Question 17

Input will be a matrix consiting of only 1’s n 0’s.

The 1’s represent the lines and 0’s its absence.

For eg a matrix 6X7 is shown

0 0 0 1 1 1 1

0 1 1 1 0 1 1

0 1 0 1 0 1 1

0 1 0 1 0 1 1

0 1 1 1 0 1 1

0 0 0 1 1 1 1

In the above matrix, the sequence of 1’s represents the lines. These eight lines constitute three

rectangles.

Conditons :

1. The rectangles will always enclose some 0’s. e.g. last two vertical lines does not constitute a

rectangle.

2. A rectangle can contain multiple rectangles

Output : should be no. of rectangles formed in the matrix(intersecting rectangles are also counted).

KodNest Training New Batch is starting on 15th July 2020Check Now

New Report

Close