commit 378592e743fe6936190a75b51a8da1d3df7d087a
parent 80048f468eba5a4d8a1b3ca1d82731fe5c012999
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Sat, 10 Aug 2024 12:59:14 +0200
1 Random Problem
Diffstat:
2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/Problems/3239.cpp b/Problems/3239.cpp
@@ -0,0 +1,21 @@
+class Solution {
+ public:
+ int minFlips(const vector<vector<int>> &grid) const {
+ const int n = size(grid), m = size(grid[0]);
+ int row = 0, col = 0;
+
+ for (int i = 0; i < n; i++) {
+ int a = 0, b = m - 1;
+ while (a < b)
+ row += grid[i][a++] != grid[i][b--];
+ }
+
+ for (int j = 0; j < m; j++) {
+ int a = 0, b = n - 1;
+ while (a < b)
+ col += grid[a++][j] != grid[b--][j];
+ }
+
+ return min(row, col);
+ }
+};
diff --git a/README.md b/README.md
@@ -1314,3 +1314,4 @@ for solving problems.
| 3211 | Medium | [Generate Binary Strings Without Adjacent Zeros](Problems/3211.cpp) |
| 3212 | Medium | [Count Submatrices With Equal Frequency of X and Y](Problems/3212.cpp) |
| 3228 | Medium | [Maximum Number of Operations to Move Ones to the End](Problems/3228.cpp) |
+| 3239 | Medium | [Minimum Number of Flips to Make Binary Grid Palindromic I](Problems/3239.cpp) |