<prompt> Kutokana na m x n binary matrix kujazwa na 0 na 1, kupata kubwa mstatili yenye 1 tu na kurudi eneo lake. code ni katika Python, tafadhali.  <response>: Heres a possible implementation using a stack:def maximalRectanglematrix: if not matrix: return 0 m, n lenmatrix, lenmatrix0 heights 0 n max_area 0 for i in rangem: for j in rangen: heightsj heightsj 1 if matrixij 1 else 0 max_area maxmax_area, largestRectangleAreaheights return max_areadef largestRectangleAreaheights: stack heights.append0 max_area 0 for i, h in enumerateheights: while stack and heightsstack-1 h: j stack.pop width i if not stack else i - stack-1 - 1 max_area maxmax_area, heightsj width stack.appendi return max_areaThe maximalRectangle function takes a binary matrix and calculates the largest rectangle containing only 1s, using the largestRectangleArea function. It first initializes an array heights with 0s, of length n the number of columns. It then iterates over each row of the matrix and updates the heights array accordingly by incrementing the height if the matrix element is 1 or resetting it to 0 otherwise. Finally, it calculates the largest rectangle area that can be formed using the heights array, and updates the max_area variable if a bigger area is found.The largestRectangleArea function takes an array of heights and finds the largest rectangle that can be formed using these heights. It does this by iterating over the heights and maintaining a stack of indices representing the bars of the rectangle. For each bar, it pops all bars from the stack whose height is greater than or equal to the current bars height, and calculates the area of the rectangle formed by the bar and the popped bars. The width of the rectangle is calculated as the distance between the bar and the last bar remaining on the stack or 0 if the stack is empty. The maximum area found during this process is returned. 