Question

In: Computer Science

def largest_rectangle_in_matrix(matrix: List[List[int]]) -> int: """ Returns the area of the largest rectangle in <matrix>. The...

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

Solutions

Expert Solution

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. #####


Related Solutions

from typing import List def longest_chain(submatrix: List[int]) -> int: """ Given a list of integers, return...
from typing import List def longest_chain(submatrix: List[int]) -> int: """ Given a list of integers, return the length of the longest chain of 1's that start from the beginning. You MUST use a while loop for this! We will check. >>> longest_chain([1, 1, 0]) 2 >>> longest_chain([0, 1, 1]) 0 >>> longest_chain([1, 0, 1]) 1 """ i = 0 a = [] while i < len(submatrix) and submatrix[i] != 0: a.append(submatrix[i]) i += 1 return sum(a) def largest_rectangle_at_position(matrix: List[List[int]], x:...
def warmer_year(temps_then: List[int], temps_now: List[int]) -> List[str]: """Return a list of strings representing whether this year's...
def warmer_year(temps_then: List[int], temps_now: List[int]) -> List[str]: """Return a list of strings representing whether this year's temperatures from temps_now are warmer than past temperatures in temps_then. The resulting list should contain "Warmer" at the indexes where this year's temperature is warmer, and "Not Warmer" at the indexes where the past year was warmer, or there is a tie. Precondition: len(temps_then) == len(temps_now) >>> warmer_year([10], [11]) ['Warmer'] >>> warmer_year([26, 27, 27, 28], [25, 28, 27, 30]) ['Not Warmer', 'Warmer', 'Not Warmer',...
from partition import partition def quicksort(a: list, l: int, u: int) -> None: '''Sort the given...
from partition import partition def quicksort(a: list, l: int, u: int) -> None: '''Sort the given list a in non-descending order. Precondition: 0 <= l and u < len(a)''' if l < u: mid = (l + u) // 2 three = [a[l], a[mid], a[u]] three.sort() if three[1] == a[l]: pivot_loc = l elif three[1] == a[u]: pivot_loc = u else: pivot_loc = mid a[u], a[pivot_loc] = a[pivot_loc], a[u] pivot = a[u] i = partition(a, l, u - 1, pivot)...
Qno.1 Part(A). IN jAVA if 1.Int abc; 2. Int def = 8; 3. abc = def;...
Qno.1 Part(A). IN jAVA if 1.Int abc; 2. Int def = 8; 3. abc = def; ➢ Describe the procedure how much memory will be allocated when these three lines of codes will execute. ➢ Describe what will happened after execution of each of these line of code in term of memory allocation and data storage Qno.1 Part(B) A capacitor is constructed from two conductive metal plates 30cm x 50cm which are spaced 6mm apart from each other, and uses...
/* calculating area of a circle, calculating area of a rectangle, calculating area of a triangle,...
/* calculating area of a circle, calculating area of a rectangle, calculating area of a triangle, and quit. */ import java.util.Scanner; public class GeoCalculator {    public static void main(String arg[]) { int geoCalc; //number selection of user Scanner get = new Scanner(System.in); //display section. System.out.println("Geometry Calculator"); System.out.println("Please select from the following menu:"); System.out.println("1. Calculate the Area of a Cirlce."); System.out.println("2. Calculate the Area of a Rectangle."); System.out.println("3. Calculate the Area of a Triangle."); System.out.println("4. QUIT"); System.out.println("Please make a selection:...
package applications; public class Matrix { private int[][] m; public Matrix(int x, int y) { m...
package applications; public class Matrix { private int[][] m; public Matrix(int x, int y) { m = new int[x][y]; } public Matrix(int x, int y, int z) { m = new int[x][y]; for(int i = 0; i < x; i++) { for(int j = 0; j < y; j++) { m[i][j] = z; } } } public int rowsum(int i) throws IndexOutOfBoundsException { if (i < 0 || i > m.length-1) { throw new IndexOutOfBoundsException("Invalid Row"); } int sum =...
Complete the following methods: secondlargest(): returns the second largest in the list without sorting. Assumes list...
Complete the following methods: secondlargest(): returns the second largest in the list without sorting. Assumes list has at least 2 elements. palindrome(): checks if list elements are palindrome, i.e. list elements from left to right and right to left, are identical. Code: import java.util.*; import java.io.*; public class xxxxxL1 {    // class Variables     private int n, count, arr[];    PrintStream prt = System.out;    // xxxxxL1 Constructor    xxxxxL1(int k){       count = 0;       n...
The area of a particular rectangle is 12 times the area of a certain square, and...
The area of a particular rectangle is 12 times the area of a certain square, and the width of the rectangle is three times the length of a side of the square. The perimeter of the rectangle is 30 units greater than the perimeter of the square. Find the dimensiuons of both the rectangle and the square.
a function named area to calculate the area of a rectangle area = Length x width...
a function named area to calculate the area of a rectangle area = Length x width 2.a function named volume to calculate the volume of a sphere volume = 4/3 x 3.14 x radius x radius x radius 3.a function named volume to calculate the volume of a cuboid volume = Length x width x ht 4. Use a loop structure to calculate the sum of all odd numbers from 1 to 17 5) Use a loop structure to calculate...
Find the maximum area of a rectangle inscribed in a triangle of area A.(NOTE: the triangle...
Find the maximum area of a rectangle inscribed in a triangle of area A.(NOTE: the triangle need not necessarily be a right angled triangle).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT