• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
December 27, 2023 |460 Views
PROBLEM OF THE DAY : 26/12/2023 | Largest rectangular sub-matrix whose sum is 0
Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Yash Dwivedi. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Matrix but also build up problem-solving skills.

In this problem, we are given a matrix mat[][] of size N x M. The task is to find the largest rectangular sub-matrix by area whose sum is 0.

If there are multiple solutions return the rectangle which starts from the minimum column index. If you still have multiple solutions return the one having the least width (number of columns included in the sub-matrix) starting from the minimum row index. If no such matrix is present return a zero (0) size matrix.

Example :

Input: N = 3, M = 3
mat[][] =  1, 2, 3
               -3,-2,-1
                 1, 7, 5

Output:  1, 2, 3
              -3,-2,-1

Explanation: This is the largest sub-matrix, whose sum is 0.

Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/largest-rectangular-sub-matrix-whose-sum-is-0/1