Largest area of rectangle with permutations interviewbit solution
Answers
Answered by
3
We have discussed a dynamic programming based solution for finding largest square with 1s.
In this post an interesting method is discussed that uses largest rectangle under histogram as a subroutine. Below are steps. The idea is to update each column of a given row with corresponding column of previous row and find largest histogram area for for that row.
Step 1: Find maximum area for row[0] Step 2: for each row in 1 to N - 1 for each column in that row if A[row][column] == 1 update A[row][column] with A[row][column] += A[row - 1][column] find area for that row and update maximum area so far
Illustration :
step 1: 0 1 1 0 maximum area = 2 step 2: row 1 1 2 2 1 area = 4, maximum area becomes 4 row 2 2 3 3 2 area = 8, maximum area becomes 8 row 3 3 4 0 0 area = 6, maximum area
In this post an interesting method is discussed that uses largest rectangle under histogram as a subroutine. Below are steps. The idea is to update each column of a given row with corresponding column of previous row and find largest histogram area for for that row.
Step 1: Find maximum area for row[0] Step 2: for each row in 1 to N - 1 for each column in that row if A[row][column] == 1 update A[row][column] with A[row][column] += A[row - 1][column] find area for that row and update maximum area so far
Illustration :
step 1: 0 1 1 0 maximum area = 2 step 2: row 1 1 2 2 1 area = 4, maximum area becomes 4 row 2 2 3 3 2 area = 8, maximum area becomes 8 row 3 3 4 0 0 area = 6, maximum area
Similar questions