In: Computer Science
def largest_rectangle_in_matrix(matrix: List[List[int]]) ->
int:
"""
Returns the area of the largest rectangle in <matrix>.
The area of a rectangle is defined as the number of 1's that it contains.
Again, you MUST make use of
<largest_rectangle_at_position> here. If you
managed to code largest_rectangle_at_position correctly, this
function
should be very easy to implement.
Similarly, do not modify the input matrix.
Precondition:
<matrix> will only contain the integers 1 and 0.
>>> case1 = [[1, 0, 1, 0, 0],
... [1, 0, 1, 1, 1],
... [1, 1, 1, 1, 1],
... [1, 0, 0, 1, 0]]
>>> largest_rectangle_in_matrix(case1)
6
"""
pass
RAW CODE
from typing import List
def largest_rectangle_in_matrix(matrix: List[List[int]]) -> int:
maximum = max([sum(L) for L in matrix]) ## Sum The lists inside list and print maximum value among them
print(maximum)
case1 = [[1, 0, 1, 0, 0],[1, 0, 1, 1, 1],[1, 1, 1, 1, 1],[1, 0, 0, 1, 0]]
### Here Maximum 1 in 3rd Rectangle i.e. 5
largest_rectangle_in_matrix(case1)
SCREENSHOT (CODE WITH OUTPUT)
##### FOR ANY QUERY, KINDLY GET BACK, THANKYOU. #####