From cb64d5b8baec0d8cd48dd28645b46a3bf50c48b3 Mon Sep 17 00:00:00 2001 From: chayan das Date: Mon, 25 Aug 2025 01:02:40 +0530 Subject: [PATCH] Create 3197. Find the Minimum Area to Cover All Ones II --- ...Find the Minimum Area to Cover All Ones II | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 3197. Find the Minimum Area to Cover All Ones II diff --git a/3197. Find the Minimum Area to Cover All Ones II b/3197. Find the Minimum Area to Cover All Ones II new file mode 100644 index 0000000..890079e --- /dev/null +++ b/3197. Find the Minimum Area to Cover All Ones II @@ -0,0 +1,89 @@ +class Solution { +public: + vector> rotateClockwise(vector>& grid){ //to rotate the matrix + int m = grid.size(); + int n = grid[0].size(); + + vector> rotatedGrid(n, vector(m)); + for(int i = 0; i>& grid) { //find min area that contains all ones + int m = grid.size(); + int n = grid[0].size(); + + int maxRow = 0; + int maxCol = 0; + int minRow = m - 1; + int minCol = n - 1; + + for(int i = startRow; i>& grid){ //solving the first three cases + int m = grid.size(); + int n = grid[0].size(); + + int result = INT_MAX; + + for(int rs = 1; rs>& grid) { + int result = helper(grid); + + vector> rotatedGrid = rotateClockwise(grid); + + result = min(result, helper(rotatedGrid)); + + return result; + } +};