Average Rent In Los Angeles For 2-bedroom, 12 Bridges High School Football Schedule, Ayden Elementary School, Articles L

A question remains: what does "largest" submatrix, or equivalently "largest" biclique mean? Find largest rectangle containing only zeros in an NN binary matrix Contribute your expertise and make a difference in the GeeksforGeeks portal. 600), Medical research made understandable with AI (ep. 0 & 0 & 0 & 0 & 0 \\ You can easily write a dynamic programming equation of S(x,y) from the value of S(x-1,y), S(x,y-1) and S(x-1,y-1). Largest Rectangular Area in a Histogram using Stack c++ - Finding largest rectangle in 2D array - Stack Overflow matrix - Finding the largest rectangular submatrix We need to remember this one. Was there a supernatural reason Dracula required a ship to reach England in Stoker? Blurry resolution when uploading DEM 5ft data onto QGIS. We can attack the 2nd problem in multiple ways. \begin{array}{cccccc} I have a sparse non-symmetric binary matrix with a block structure. What's the meaning of "Making demands on someone" in the following context? 1 & 1 & 1 & 1 & 1 \\ Can fictitious forces always be described by gravity fields in General Relativity? According to Knig's theorem, in bipartite graphs, the minimum vertex cover can be formed from a maximum matching. 1&1&0&1&1&1\\ Here is a version of jfs' solution, which also delivers the position of the largest rectangle: from collections import namedtuple from operator import mul Info = WebGiven an m x n matrix matrix and an integer k, return the max sum of a rectangle in the matrix such that its sum is no larger than k. It is guaranteed that there will be a rectangle 1 & 0 & 0 & 0 & 0 \\ How much of mathematical General Relativity depends on the Axiom of Choice? What is the meaning of the blue icon at the right-top corner in Far Cry: New Dawn? Why do "'inclusive' access" textbooks normally self-destruct after a year or so? \hline Use your matrix. \end{array}$. What is the word used to describe things ordered by height? I have a function to find 1 largest rectangle for a particular label called def find_largest_rect(). var best = {area: 0} Thanks Jerry, there seem to be two issues: 1 the largest sub-matrix in the example is 5x3, your answer results in (after transpose) a 6x3 sub-matrix; Also, I am concerned the Subset will explode beyond memory capacity once we work with large matrices? I've edited my answer to include what I think may be a more efficient "second step. Plotting Incidence function of the SIR Model. First of all consider every 0 in the matrix as -1. Consider a function S(x,y) such that S(x,y) holds the area of the largest rectangle where (x,y) are the lowest-right-most corner cell of the rectangle; x is the row co-ordinate and y is the column co-ordinate of the rectangle. nice!! So how can I find The tricky part is coding up the routine that runs along the scan line updating the active list. You are now done with scan line 0, so you increment your scan line. Not the answer you're looking for? They examine the data one row (or scan line) at a time building up the answer you are looking for, in your case candidate rectangles. We can interpret your matrix $A$ as a bipartite incidence matrix: $a_{ij}=1$ means that vertex $i$ of the first partition is connected to vertex $j$ of the second partition of a bipartite graph. Now, the idea is to reduce the problem to 1-D array. It is replaced with two new active ones: (4,0,4,2) and (9,0,1,2). What happens if you connect the same phase AC (from a generator) to both sides of an electrical panel? 1 & 1 & 1 & 1 & 1 \\ Thanks for contributing an answer to Stack Overflow! \end{array} \hline I'm not going to post pseudo-code for this because the idea is completely experimental, and I have no idea if the perf will be any better for a loose pixel grid ;). Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. Thanks, unfortunately . its mostly rectangular squares I am dealing with here. Do Federal courts have the authority to dismiss charges brought in a Georgia Court? Please don't take this as being condescending; I did not come up this answer on the spot. It only takes a minute to sign up. 1 & 1 & 1 & 1 & 1 & 1 \\ 1 & 1 & 1 & 1 & 0 \\ So it's pretty impressive to see someone working through the problem! The dimensions of the matrix are thousands rows and less than one hundred columns. Accept a SOUTHERN neighbor with a smaller length if doing so will increase the area of the rectangle. The easiest is to reduce it to simple clique finding: connect all vertex pairs within each of the two partitions, and look for maximum cliques. The lower bound is. Start here for a quick overview of the site, Detailed answers to any questions you might have, Discuss the workings and policies of this site. 0&0&0&1&1&1\\ would be a thorough, but maybe not-the-most-efficient way to go about it. It is the largest we have seen to far. This article is being improved by another user right now. This list is sorted by increasing x coordinate. \end{array} \right)$. It is a little tricky to describe. ", The problem with your second algorithm is that you need a. \hline How is this related to graphs and networks? S(8,5)=40, which says that the largest rectangle for which the lowest-right cell is (8,5) has the area 40, which happens to be the optimum solution in this example. How do I reliably capture the output of 'ls' in this script? Asking for help, clarification, or responding to other answers. \{2,4,5\} & \{1,2,4,5,6\} & 15 \\ Its's fairly easy to bound the area of the rectangular submatrix, in order to restrict the search quite a bit. \left\{\left( I would like to recover the coordinates of where the sub-matrix is residing. WebYou need to find the biggest rectangle in that matrix that consists of only 1s Input format: The first line consists of two space-separated integers, N and M representing the rows It seems that you need a more stringent condition; if your current condition is satisfied for a small isolated submatrix of 1s, you miss a larger block in other parts of the input matrix. Bonus if you can solve it in rev2023.8.22.43591. C++ has nothing to do with the question. WebThis lecture explains a very popular programming interview question which is to find the largest rectangle in histogram.Given an array representing heights of each bar in a Awesome, this is exactly what I was looking for. 9}, {4, {4, 6}, 12}, {5, {4, 6}, 15}}. I have nothing at the moment. WebGiven a rectangular binary matrix, calculate the area of the largest rectangle of 1's in it. The function stutteringAccumulate is from the posts by ciao and by Chip Hurst. Is it rude to tell an editor that a paper I received to review is out of scope of their journal? Share your suggestions to enhance the article. Time Complexity: O(n3) Auxiliary Space: O(n) This article is contributed by Ayush Jauhari. Get all permutations of rows and cols, skipping the first which is just { }. Largest Rectangle in Matrix - Coding Ninjas If a line == a thin rectangle, you could optimize further by: Use the first method to check your work. By clicking Post Your Answer, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct. How do I identify the largest non-contiguous rectangular sub-matrix consisting only of 1 -entries? 1 & 0 & 0 & 1 & 1 \\ At each point we are looping through the width of the matrix to find the largest rectangle at that point, this slows the complexity to w*h*w. So the complexity is: O(w*h) Submatrix with most elements = biclique with most edges. rev2023.8.22.43591. Is it reasonable that the people of Pandemonium dislike dogs as pets because of their genetics? 0 & 0 & 9 & 0 & 0 \\ I am the author of the Maximal Rectangle Solution on LeetCode, which is what this answer is based on. Since the stack-based solution has already \begin{array}{cccccc} 1 & 1 & 0 & 0 & 1 \\ \begin{array}{cccccc} In this case, one of the solutions happens to also have the most element ($4 \times 5 = 20$). Using that you can obtain the values of all S(x,y) in O(mn) time, where m and n are the row and column dimension of the given table. For both sub-matrices, $4+5 = 3+6 = 9$. 1 & 1 & 1 & 1 & 1 & 1 \\ c++ - Finding largest rectangle in 2D array - Stack Overflow Once, S(x,y) are know for all 1<=x <= m, and for all 1 <= y <= n, we simply need to find the x, and y for which S(x,y) is the largest; this step also takes O(mn) time. By clicking Post Your Answer, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct. For example, in your figure, S(1,1) = 1, S(1,2)=2, S(2,1)=2, and S(2,2) = 4. Then we just need to look for maximal cliques to find maximal bicliques. I'm the author of that Dr. Dobb's article and get occasionally asked about an implementation. \hline For reference, look at the image I made demonstrating my question. If you are actually starting out with rectangular data (for your "populated grid" set), instead of a loose pixel grid, then you could easily get better perf out of a rectangle/region subtracting algorithm. A-143, 9th Floor, Sovereign Corporate Tower, Sector-136, Noida, Uttar Pradesh - 201305, We use cookies to ensure you have the best browsing experience on our website. Edit The pattern is either very sparse, or there are very few Submatrix with most #rows + #columns in total = biclique with most vertices. But, S(3,1)=0, because this cell is filled. Does it need to be a square? There are multiple interpretations, e.g. Example: In the sample image given, take the square closest to the lower-right-hand corner and move it all the way to the left. Windows system "regions" and "dirty rectangles", as well as general "temporal caching" might be good inspiration here for more efficiency. \text{rows} & \text{columns} & \text{area} \\ I'm the author of that Dr. Dobb's article and get occasionally asked about an implementation. Here is a simple one in C: #include Plus, it is often useful to code up an obviously correct solution before you worry about bug-finding in more clever solutions. @Ben thanks. To get the largest rectangle full of 1s, update the next row with the previous row and find the largest area under the histogram, i.e. for (int i=0; i < M; i++) { $ \right) Largest area rectangular sub-matrix with equal number of 1s and 0s The pattern is either very sparse, or there are very few large submatrices. Browse other questions tagged. Making statements based on opinion; back them up with references or personal experience. My bad, I meant to say rectangle. In the simplified example below, it would be elements {2, 1} towards {2,6} and {5,1} towards {6,6}. \{2,4,5,6\} & \{1,2,4,5,6\} & 20 \\ @lassevk I found the referenced article, from DDJ: The Maximal Rectangle Problem obstacles which split existing rectangles, obstacles which require you to remove a rectangle from the active list, Active List: (0,1,8,1), (1,0,2,2), (4,0,4,2), (9, 0, 1, 2), grow NORTH as far as possible by adding rows, grow SOUTH as far as possible by adding rows, save the resulting area for the seed pixel used, After looping through each point in ARRAY, pick the seed pixel with the largest area result, Create a second array of integers called LINES that has the same dimensions as ARRAY. ADDENDUM:Several edits later, I think this answer deserves a group upvote. How much of mathematical General Relativity depends on the Axiom of Choice? algorithm - Finding rectangles in a 2d block grid - Stack There is a function in Mathematica for finding a maximum matching: FindIndependentEdgeSet. Find the largest rectangle for each row of histograms: {{1, {1, 4}, 4}, {2, {1, 4}, 8}, {2, {4, 6}, 6}, {3, {4, 6}, @user422382: No problem. In fact, for this matrix, the ideal works out to 8. The zero values mean in the worst case, it is possible to order the values in the rows so that there is no overlap of all terms. So you know that your submatrix rectangle at least has an area of 8, and no more than 12. Merge Sort - Data Structure and Algorithms Tutorials, QuickSort - Data Structure and Algorithm Tutorials, Bubble Sort - Data Structure and Algorithm Tutorials, Tree Traversal Techniques - Data Structure and Algorithm Tutorials, Binary Search - Data Structure and Algorithm Tutorials, Insertion Sort - Data Structure and Algorithm Tutorials, Selection Sort Data Structure and Algorithm Tutorials, Count rotations in sorted and rotated linked list, Program to find Circumference of a Circle. You should update your first piece of code. Here's a rough outline of how it would work. Explanation 2. public class Test { To find the top and bottom row numbers, calculate sum of elements in every row from left to right and store these sums in an array say temp[]. This algorithm is suboptimal. Largest rectangle in Matrix 3 = 3 units. \end{array} 0 & 0 & 0 & 0 & 1 \\ \left( I think Knuth said "premature optimization is the root of all evil.". Having trouble proving a result from Taylor's Classical Mechanics. As the largest rectangular area for each seed is calculated, check to see if you have a new max value and save the result if you do. Find the largest rectangular area possible in a given histogram where the largest rectangle can be made of a number of contiguous bars whose heights are given 1&1&1&1&0&0\\ If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. At least you helped me a lot by giving me a fun challenge to see if I can work with your answer as a basis. Data Structure & Algorithm Classes (Live), Data Structure & Algorithm-Self Paced(C++/JAVA), Full Stack Development with React & Node JS(Live), Top 100 DSA Interview Questions Topic-wise, Top 20 Interview Questions on Greedy Algorithms, Top 20 Interview Questions on Dynamic Programming, Top 50 Problems on Dynamic Programming (DP), Commonly Asked Data Structure Interview Questions, Top 20 Puzzles Commonly Asked During SDE Interviews, Top 10 System Design Interview Questions and Answers, Indian Economic Development Complete Guide, Business Studies - Paper 2019 Code (66-2-1), GATE CS Original Papers and Official Keys, ISRO CS Original Papers and Official Keys, ISRO CS Syllabus for Scientist/Engineer Exam, Check if possible to cross the matrix with given power, Maximum weight path ending at any element of last row in a matrix, Check whether row or column swaps produce maximum size binary sub-matrix with all 1s, Minimum sum submatrix in a given 2D array, Collect maximum coins before hitting a dead end, Maximum sum path in a matrix from top to bottom and back, Minimum time required to rot all oranges | Dynamic Programming, Maximum sum path in a matrix from top to bottom, Maximum points collected by two persons allowed to meet once, Check if it is possible to get given sum by taking one element from each row, Maximum path sum that starting with any cell of 0-th row and ending with any cell of (N-1)-th row, Maximise matrix sum by following the given Path, Maximum non-negative product of a path from top left to bottom right of given Matrix. I have done extensive professional work that involves algorithms just like this. The two active rectangles are (1,0,2,1) and (4,0,6,1). The maximum edge biclique problem is NP-complete, meaning that there is no fast exact solution for large cases. WebLargest rectangle in Matrix 1 = 6 units. This is the only suggested answer with a correct algorithm. Apologies, there is a larger selection possible in my answer that I omitted. Max Sum of Rectangle No Larger Than K - LeetCode Use. $. Based on this explanation. 0 & 0 & 1 & 0 & 1 \\ Update: This answer is not correct but for referencing, because the Subsets does not give all the possible slices of the matrix. Examples: The naive solution for this problem is to check every possible rectangle in given 2D array by counting the total number of 1s and 0s in that rectangle. The function poP is a slightly modified version of Pop from rosettacode - Stack. Find where it is at, noting that there may be multiple solutions. I was wondering, that's all. By using our site, you Is there an accessibility standard for using icons vs text in menus? Try, for example, Finding the largest rectangular submatrix, The maximum edge biclique problem is NP-complete, http://tryalgo.org/en/matching/2016/08/05/konig/, Maximum Size Rectangle of All 1's Dynamic Programming, Semantic search without the napalm grandma exploit (Ep. \end{array} \{2,4,6\} & \{1,2,4,5,6\} & 15 \\ Given a binary matrix. We fix the left and right columns one by one and find the largest sub-array with 0 sum contiguous rows for every left and right column pair. However, the blocks are likely to overlap. Enhance the article with your expertise. It's just there are a lot of students on right now posting homework problems with no work, so basically asking people to do their homework for them :) I figured a high level generic answer was enough of a hint, if this happened to be the case. \hline The naive solution for this problem is to check every possible rectangle in given 2D array. \left( 1 & 1 & 1 & 1 & 1 & 1 \\ Securing Cabinet to wall: better to use two anchors to drywall or one screw into stud? The following code looks for all maximal cliques: Here's some code to convert these to row/column indices and highlight them in the graph: Once again, this method does not find submatrices which have the most elements. \right) 1 & 1 & 1 & 0 & 0 \\ \left( This will duplicate a lot of work (for example you will re-evaluate a lot of sub-rectangles), but it should give you an answer. \right)\right\} The idea to find the area of the largest 1 filled Determine the longest valid line to the EAST that begins at each point and save its length in the corresponding cell of LINES. Why do people generally discard the upper portion of leeks? 1 & 1 & 1 & 0 & 0 \\ Why not just grow in two directions rather than all four? You add these to a list of active rectangles. Examining row 0 you have the beginnings of two rectangles (I am assuming you are only interested in the black square). Thanks again for letting me know, I will be extra careful knowing that ;-), Semantic search without the napalm grandma exploit (Ep. All the others take shortcuts that may eliminate the optimal result. Maximum size of rectangle in a binary matrix Author Pranav Gautam 0 upvotes Table of contents 1. Fortunately, this is only for a hobby project I am working on. 4, 3, 3}, {2, 2, 1, 5, 4, 4}, {3, 3, 2, 6, 5, 5}}. f The idea of using an increasing stack to find the largest rectangle in a histogram and implementation is from this answer by Pei. Max Rectangle in Binary Matrix | InterviewBit 0 & 0 & 0 & 0 & 0 \\ By keeping addition data, you can also find the side-length of the largest rectangle. To subscribe to this RSS feed, copy and paste this URL into your RSS reader. Will try to understand this do you think the, @Sanders, although we are considering only 2-subsets of the non-zero positions. I'm just not sure how to implement such an algorithm. 0 & 0 & 0 & 8 & 0 \\ There are also a lot of z-buffer tricks if this is for a graphics algorithm Use dynamic programming approach. // for topleft corner. $. I suppose you need to answer the philosophical question "Is a line of points a skinny rectangle?" Go back and get the particular rows and columns. This finds ONLY SQUARE sub matrix. Maximum vertex biclique finding is equivalent to finding a maximum independent vertex set in the bipartite complement graph. I believe you want the 1st interpretation, but this does not seem to have fast solutions. Just take the first. Thanks for support and background; still digesting your answer, a lot of knowledge there @Sander Actually, I learn as I go your question was an opportunity to learn some new things. 1 & 1 & 1 & 1 & 1 \\ \hline Update 2: Dealing with non-necessarily-contiguous case for small matrices: $\begin{array}{|c|c|c|} @Perry, thank you. A brute brain force approach as well, thanks. Find centralized, trusted content and collaborate around the technologies you use most. Given a binary matrix M of size n X m. Find the maximum area of a rectangle formed only of 1s in the given Your LINES array concept is close. Find the area of the largest rectangle of 1s in a binary matrix For each point in LINES, determine how many neighbors SOUTH have the same length value or less. Output 1.3. For the upper bound, count the number of 1's in each row, and then sort on that, large to small. What does soaking-out run capacitor mean? Hope this helps. Pick from largestrecs the one with largest area: With SeedRandom[1]; mat = RandomInteger[1, {20, 40}]; as input. I like a region growing approach for this. \hline To learn more, see our tips on writing great answers. I suspect I will run into constraints when applying the, There is an explanation for rectangle matrix which I don't quite understand. Implementation of the stack-based algorithm in plain Javascript (with linear time complexity): function maxRectangle(mask) { This is more a question about algorithms. \end{array} \hline 600), Medical research made understandable with AI (ep. acknowledge that you have read and understood our. Largest rectangular sub-matrix whose sum is 0 - GeeksforGeeks Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide, The future of collective knowledge sharing. \hline 1&1&1&1&1&1\\ Mathematica is a registered trademark of Wolfram Research, Inc. It finds those for which #row + #columns is maximal. 1 & 1 & 1 & 1 & 1 & 1 \\ 0 & 10 & 0 & 0 & 0 \\ Potential shapes can be seen $ This method will omit those submatrices smaller than 2*2 : As the initMat from Okkes Dulgerci's answer: Thanks for contributing an answer to Mathematica Stack Exchange! finding complete bipartite graphs. Create a random matrix 8 rows by 5 columns, $ Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. To understand more on this, Read Chapter 15 or Cormen's algorithm book, specifically Section 15.4. What is your data structure? If we find largest subarray with 0 sum in temp[], we can get the index positions of rectangular sub-matrix with sum equal to 0 (i.e. WebMax Rectangle in Binary Matrix - Given a 2D binary matrix filled with 0s and 1s, find the largest rectangle containing all ones and return its area. Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. having equal number of 1s and 0s). 1 & 1 & 1 & 1 & 1 \\ @lassevk // 4. Outer double-for-loop to consider all possible positions The overall complexity is O(mn). Making statements based on opinion; back them up with references or personal experience. Is there a way to smoothly increase the density of points in a volume using the 'Distribute points in volume' node? This, in turn, is equivalent to finding a minimum vertex cover: the vertices not in the covert will form the independent vertex set. having equal number of 1s and 0s). WebMax rectangle. Let us take this bipartite graph, and connect all vertex pair within each of the two partitions. Largest rectangle in Histogram | Leetcode #84 - YouTube This solution Would there be more efficient methods of computing this rather then looping through each possibilities, or is that the only way? Is there any other sovereign wealth fund that was hit by a sanction in the past? Now I will be able to make my game more efficient. Here's a brute force for the non-contiguous rectangular submatrix. 1 & 1 & 0 & 0 & 0 \\ 1 & 0 & 0 & 0 & 0 \\ I need an algorithm which can parse a 2D array and return the largest continuous rectangle. \right) A biclique is a complete bipartite subgraph (of a bipartite graph). Thanks for telling me, I fixed it. Input 1.2. $. \hline I am not an expert but would like to understand why, based on your statement: "Maximum vertex biclique finding is equivalent to finding a maximum independent vertex set in the bipartite complement graph." \end{array} Help us improve. I added the size (thousands long, less than a hundred wide and that I am looking for non-contiguous solutions. There might be optimization opportunities here using quadtrees, and in ensuring that you keep split rectangles "in order", top to bottom, left to right, in case you need to re-combine rectangles farther down in the algorithm. Assume that a rectangle can be formed by swapping any number of columns with each How do I identify the largest non-contiguous rectangular sub-matrix consisting only of 1-entries? How do you determine purchase date when there are multiple stock buys? Largest rectangular sub-matrix whose sum is 0 Try It! Largest rectangle in Matrix 2 = 5 units. With this process we can find the largest area rectangular sub-matrix with sum equal to 0 (i.e. 8 & 0 & 0 & 0 & 0 \\ Asking for help, clarification, or responding to other answers. Largest Rectangle in a Matrix - Towards Data Science So for example, you need to see if combinations of 4 (from 8) rows and 3 (from 5) columns result in a successful submatrix. 1&1&1&1&1&1\\ So temp[i] indicates sum of elements from left to right in row i. (It is not unlikely that his discrete optimization problem is very hard), If you want non-contiguous too, then this is indeed the clique problem, which is NP-complete, and there's not going to be a simpler solution. Parse a 2D array of what? \begin{array}{ccccc} idz's answer is preferred. And you can get the subsets to search over (corresponding to the coordinates of the non-zero elements in the matrix above). TV show from 70s or 80s where jets join together to make giant robot, Plotting Incidence function of the SIR Model. 1 & 1 & 1 & 1 & 1 \\ For the lower bound, it's a little quirky to calculate. import java.util.Stack; Might there be an additional structure behind the matrix? This solution requires 4 nested loops and time complexity of this solution would be O(n^4). Finding the area of the largest rectangle in a binary matrix \hline Sorry I was not clear. 1 & 1 & 1 & 1 & 1 & 1 \\ Maximum size of rectangle in a binary matrix - Coding Ninjas it's very insight- and usefull nonetheless. 1 & 1 & 1 & 1 & 0 & 0 \\ With this process we can find the largest area rectangular sub-matrix with sum equal to 0 (i.e. \{2,3,4,5,6\} & \{4,5,6\} & 15 \\ An alternate approach might be to start with a single square the size of the grid, and "subtract" occupied squares to end up with a final set of potential rectangles. consider each 1s as filled \begin{array}{ccccc} 601), Moderation strike: Results of negotiations, Our Design Vision for Stack Overflow and the Stack Exchange network, Given a large binary matrix, find the largest submatrix containing non-zero elements, Principal submatrix and Principal minor of a matrix, Replace elements of a matrix with zeros using another matrix, Fastest way to update rows of an array of SparseArrays, Finding the largest disk within a convex region using Region primitives, Root finding in a non-rectangular solution region. We can use Hashing technique MathJax reference. Was there a supernatural reason Dracula required a ship to reach England in Stoker? The best answers are voted up and rise to the top, Not the answer you're looking for? The largest rectangle using that seed point is (Number_of_acceptable_southern_neighbors*the_length_of_longest_accepted_line). Max rectangle | Practice | GeeksforGeeks This problem can be solved in polynomial time by reducing it to bipartite matching. \{2,5,6\} & \{1,2,3,4,5,6\} & 18 \\ Use MathJax to format equations. How can I select four points on a sphere to make a regular tetrahedron so that its coordinates are integer numbers? \{2,5\} & \{1,2,3,4,5,6\} & 12 \\ or just a rectangle? What is the best way to say "a large number of [noun]" in German? So maybe this second algorithm isn't so optimized after all. Thank you for your valuable feedback! My pleasure. 1 & 1 & 1 & 1 & 1 & 1 \\ public 1 & 1 & 1 & 1 & 1 & 1 \\ As you were working through your ideas though you were getting close. We can use Hashing technique to find maximum length sub-array with sum equal to 0 in 1-D array in O(n) time. 1 & 1 & 1 & 1 & 1 & 1 \\ I'm not sure to apply Transpose to the last one of the result. Do an Outer of the possible combinations, capturing the sum of their elements but noting the ones that have a 0 in them. \begin{array}{ccccc} For each label, I want to find 2 largest rectangles.