id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n auto isPalindrome = [](const vector<int>& arr) {\n int left = 0, right = arr.size() - 1;\n while (left < right) {\n if (arr[l... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& nums) {\n int cnt =0;\n int colC = 0;\n if(nums[0].size() == 1) return 0;\n vector<vector<int>>col (nums[0].size(), vector<int>(nums.size()));\n for(int i = 0 ;i< nums[0].size();i++){\n int a = 0;... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& nums) {\n int cnt =0;\n int colC = 0;\n if(nums[0].size() == 1) return 0;\n vector<vector<int>>col (nums[0].size(), vector<int>(nums.size()));\n for(int i = 0 ;i< nums[0].size();i++){\n int a = 0;... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int count(vector<int> arr)\n {\n int cn=0;\n int n=arr.size();\n int i=0;\n int j=n-1;\n while(i<=j)\n {\n if(arr[i]!=arr[j]) cn++;\n i++;\n j--;\n }\n return cn;\n\n }\n int min... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\nprivate:\n int count_flip(vector<int> vec){\n int flips=0;\n for(int i=0;i<vec.size()/2;i++){\n if(vec[i]!=vec[vec.size()-1-i])flips++;\n }\n return flips;\n }\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int m=grid.size();\... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n \n // Function to calculate minimum flips to make a vector palindromic\n auto minFlipsToMakePalindromic = [](const vector<int>& v) -> int {\n ... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlipsToPalindrome(vector<int>& sequence) {\n int left = 0, right = sequence.size() - 1;\n int flips = 0;\n\n while (left < right) {\n if (sequence[left] != sequence[right]) {\n flips++;\n }\n left++;\... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\nbool check(string S)\n{\n // Stores the reverse of the\n // string S\n string P = S;\n \n // Reverse the string P\n reverse(P.begin(), P.end());\n \n // If S is equal to P\n if (S == P) {\n return true;\n }\n // Otherwise\n else {\n retu... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution \n{\npublic:\n int minFlips(vector<vector<int>>& grid) \n {\n int n=grid.size();\n int m=grid[0].size();\n vector<int> r(n),c(m);\n for(int i=0;i<n;i++)\n {\n vector<int> rr = grid[i];\n int p1=0,p2=m-1;\n int tr=0;\n ... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int palindromeRow(vector<int> row){\n int n=row.size();\n int ans=0;\n for(int i=0;i<n/2;i++){\n if(row[i]!=row[n-i-1]){\n ans++;\n }\n }\n return ans;\n }\n \n int minFlips(vector<vector<int>>& ... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n\n int solve(vector<int>n)\n {\n int ans=0;\n for(int i=0;i<n.size()/2;i++)\n {\n if(n[i]!=n[n.size()-1-i])\n {\n ans++;\n }\n }\n\n return ans;\n }\n int minFlips(vector<vector<int>>& ... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\nprivate:\n int count_flip(vector<int> vec){\n int flips=0;\n for(int i=0;i<vec.size()/2;i++){\n if(vec[i]!=vec[vec.size()-1-i])flips++;\n }\n return flips;\n }\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int m=grid.size();\... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution \n{\nprivate:\n int Count(vector<int> nums, int b)\n {\n int ans = 0;\n\n if(b & 1)\n {\n int a = b/2 + 1;\n for(int i = a, j = 2; i < b; i++, j += 2)\n {\n if(nums[i] != nums[i - j])\n {\n ... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlipsForRow (vector<int> arr) {\n int size = arr.size();\n int mid = size/2 - 1;\n int flips = 0;\n for (int i=0, j=size-1; i<=mid; i++, j--) {\n if (arr[i]!=arr[j]) {\n flips ++;\n }\n }\n ... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int helper(vector<int> temp){\n int f=0;\n int i=0;\n int j=temp.size()-1;\n while(i<j){\n if(temp[i]!=temp[j]){\n f++;\n }\n i++;\n j--;\n }\n return f;\n }\n int minFl... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "#include <vector>\n#include <algorithm>\n\nusing namespace std;\n\nclass Solution {\n int make_pain(vector<int>& v) {\n int i = 0;\n int cnt = 0;\n int j = v.size() - 1;\n while (i < j) {\n if (v[i] != v[j]) {\n cnt++;\n }\n i++... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n // Assuming grid is a 3x3 matrix based on the original code\n int rows = grid.size();\n int cols = grid[0].size();\n\n // Initialize variables\n vector<vector<int>> x2;\n vector<int> m1;\n ... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int mini(int a,int b){\n if(b<a) return b;\n return a;\n }\n int flips(vector<int> vec){\n int count=0;\n int i=0;\n int j=vec.size()-1;\n while(i<j){\n if(vec[i]!=vec[j]) count++;\n i++;\n j--;\... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int flipRows(vector<vector<int>> &grid ){\n int n = grid.size();\n int m = grid[0].size();\n int ans = 0;\n vector<int> v;\n for(int i=0;i<n;i++){\n v = grid[i];\n int start = 0;\n int end = m - 1;\n ... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n int a = 0;\n int b = 0;\n int res = INT_MAX;\n map<int,int>mp;\n for(int i = 0;i<n;i++)\n {\n mp[i]++;\n ... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n \n if(m == 1 || n == 1) return 0;\n int row = 0;\n int col = 0;\n\n for(int i=0 ; i<n ; i++){\n int s = 0 , e = m-1;\n ... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int countflips(vector<int>arr){\n int n = arr.size();\n int left = 0;\n int right = n-1;\n int cnt = 0;\n while(left<right){\n if(arr[left]!=arr[right])cnt++;\n left++;\n right--;\n }\n return c... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int flip(vector<int >a){\n int n=a.size();\n int ans=0;\n for(int i=0;i<n/2;i++){\n if(a[i]!=a[n-i-1]){\n ans++;\n }\n }\n return ans;\n }\n int minFlips(vector<vector<int>>& grid) {\n int m=... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlipOfALine(vector<int> line) {\n int n = line.size();\n int ans = 0;\n for (int i = 0; i < (n / 2); i++) {\n if (line[i] != line[n - 1 - i]) {\n ans++;\n }\n }\n return ans;\n }\n\n int minF... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int getCount(vector<string>& res){\n int cnt = 0;\n for(auto str:res){\n int low = 0, high = str.size()-1;\n while(low < high){\n if(str[low] != str[high])++cnt;\n ++low, --high;\n };\n ... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int cr = 0,cc=0;\n int m = grid.size();\n int n = grid[0].size();\n\n for(int i=0;i<grid.size();i++){\n if(grid[i].size()<=1) continue;\n \n vector<int> temp = grid[i];\n ... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution\n{\npublic:\n int flips_to_make_palindrome(vector<int> &nums)\n {\n int n = nums.size();\n int ans = 0;\n for (int i = 0; i < n / 2; i++)\n {\n if (nums[i] != nums[n - i - 1])\n ans++;\n }\n return ans;\n }\n\n i... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\nint k(vector<vector<int>>& grid,int i,int j)\n{\n vector<int> t1=grid[i];\n vector<int> t2=grid[j];\n int cnt=0;\n for(int l=0;l<t1.size();l++)\n {\n if(t1[l]!=t2[l])cnt++;\n }\n return cnt;\n}\nint k1(vector<vector<int>>& grid,int i,int j)\n{\n int... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int helper(vector<int>a, vector<int>b) {\n if(a==b)\n return 0;\n int count=0;\n for(int i=0;i<a.size();i++) {\n if(a[i]!=b[i])\n count++;\n }\n return count;\n }\n int minFlips(vector<vector<int>>&... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n std::vector<std::vector<int>> a = grid;\n std::vector<std::vector<int>> b = grid;\n int result_a{};\n int result_b{};\n\n for(auto& row : a){\n for(int i = 0; i < row.size()/2; i++){\n ... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n std::vector<std::vector<int>> a = grid;\n std::vector<std::vector<int>> b = grid;\n int result_a{};\n int result_b{};\n\n for(auto& row : a){\n for(int i = 0; i < row.size()/2; i++){\n ... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n std::vector<std::vector<int>> a = grid;\n std::vector<std::vector<int>> b = grid;\n int result_a{};\n int result_b{};\n\n for(auto& row : a){\n for(int i = 0; i < row.size()/2; i++){\n ... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n std::vector<std::vector<int>> a = grid;\n std::vector<std::vector<int>> b = grid;\n int result_a{};\n int result_b{};\n\n for(auto& row : a){\n for(int i = 0; i < row.size()/2; i++){\n ... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n std::vector<std::vector<int>> a = grid;\n std::vector<std::vector<int>> b = grid;\n int result_a{};\n int result_b{};\n\n for(auto& row : a){\n for(int i = 0; i < row.size()/2; i++){\n ... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n\n int f1(int row , vector<vector<int>> &grid , int colSize){\n int i = 0;\n int j = colSize-1;\n vector<int> temp = grid[row];\n int cnt = 0;\n while(i<=j){\n if(temp[i] != temp[j]){\n temp[j] = temp[i];\n ... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n\n int f1(int row , vector<vector<int>> &grid , int colSize){\n int i = 0;\n int j = colSize-1;\n vector<int> temp = grid[row];\n int cnt = 0;\n while(i<=j){\n if(temp[i] != temp[j]){\n temp[j] = temp[i];\n ... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int make_palindrome(const std::vector<int>& vec) {\n int left = 0;\n int right = vec.size() - 1;\n int cost = 0;\n\n while (left < right) {\n if (vec[left] != vec[right]) {\n cost++;\n }\n left++;\n ... |
3,526 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n return min(minR(grid,n,m),minC(grid,n,m));\n }\n\n int minR(vector<vector<int>>& grid,int n, int m){\n int cnt = 0;\n for(int i = 0; i < n; i+... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 0 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int n=grid.size();\n int m= grid[0].size();\n int totalones=0;\n int ans=0;\n for(int i=0;i<n/2;i++){\n for(int j=0;j<m/2;j++){\n int ones=0;\n if(grid[i][j... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 0 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>> &A){\n int N = A.size() , M = A[0].size();\n int Flips = 0 , OneOne = 0 , OneZero_ZeroOne = 0;\n\n for(int R = 0 ; R < (N + 1) / 2 ; R++){\n for(int C = 0 ; C < (M + 1) / 2 ; C++){\n\n int Ones = ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int l=0,r=grid[0].size()-1;\n int c=0;\n vector<int>v(max(3,(int)grid.size()),0);\n if(grid.size()%2)\n {\n while(l<r)\n { v[grid[(int)grid.size()/2][l]+grid[(int)grid.size(... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int n = grid.size(), m = grid[0].size(), sum = 0, ans = 0;\n vector<int> row(n, 0);\n for(int i = 0 ; i < n ; i++ ) {\n for(int j = 0 ; j < m ; j++ ) {\n sum += grid[i][j];\n ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\n static const int INF = 2e5;\n int nearest(int x, int lim) {\n int res = INF;\n if (x % 4 == 0) res = 0;\n if (x % 4 == 1) {\n if (x + 3 <= lim) res = min(res, 3);\n if (x - 1 >= 0) res = min(res, 1);\n }\n if (x % 4 == 2) {\n if (x + 2 <= lim) res = min(re... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int f(vector<array<int, 2>>& v) {\n int n = v.size();\n \n if (n == 0) return 0;\n \n int answer = 0;\n for (auto it : v) answer += it[1];\n \n vector<int> temp(n);\n for (int i = 0; i < n; i++) temp[i] = v[i][0] ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n pair<int,int> vecflix(vector<int> arr)\n { int n=arr.size();\n int equal_one=0,odd_one=0;\n int flip=0;\n for(int i=0;i<n/2;i++)\n {\n if(arr[i]==arr[n-i-1] && arr[i]==1)\n {\n equal_one++;\n }\n... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int n = grid.size(), m = grid[0].size(), ans = 0;\n for(int i = 0; i < n/2; ++i){\n for(int j = 0; j < m/2; ++j){\n int a = grid[i][j], b = grid[i][m-1-j];\n int c = grid[n-1-i]... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int helper(vector<int> &v){\n int n=v.size(),mismatch=0,ones=0,ans=0;\n for(int i=0;i<n/2;i++){\n if(v[i]!=v[n-i-1]) mismatch++;\n ones+=v[i]+v[n-i-1];\n }\n ones%=4;\n if(mismatch>=ones) ans+=mismatch;\n else if... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int helper(vector<int> &v){\n int n=v.size(),mismatch=0,ones=0,ans=0;\n for(int i=0;i<n/2;i++){\n if(v[i]!=v[n-i-1]) mismatch++;\n ones+=v[i]+v[n-i-1];\n }\n ones%=4;\n if(mismatch>=ones) ans+=mismatch;\n else if... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n int flip = 0;\n int ones = 0;\n\n // Step 1: Check and flip cells to make the grid palindromic\n for (int i = 0; i < n / 2; ++i) {\n ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& g) {\n int n=g.size();\n int m=g[0].size();\n int ans=0;\n int c=0;\n int nz=0,no=0;\n for(int i=0;i<(n)/2;i++)\n {\n for(int j=0;j<(m)/2;j++)\n {\n\n vector<i... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int dp[200001][4];\n int solve(int i,vector<int>&o,int cnt,int n)\n {\n if(i==n/2)\n {\n if(cnt==0)\n {\n return 0;\n }\n else\n {\n return INT_MAX;\n }\n ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "int opt[200000][4];// opt[i][j]表示nums[0:i]构成1的个数mod 4 == j情况下的最小步数\nclass Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n vector<pair<int, int>> nums;\n int m = grid.size(), n = grid[0].size();\n for (int i = 0; i <= m - 1 - i; ++i) {\n for (int j = 0; j... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class MinStack {\nprivate:\n stack<int> mainStack;\n stack<int> minStack;\n\npublic:\n MinStack() \n {\n minStack.push(INT_MAX);\n }\n\n void push(int val) \n {\n mainStack.push(val);\n minStack.push(min(val, minStack.top()));\n }\n\n void pop() \n {\n ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int row = grid.size() , col = grid[0].size() ;\n int r = grid.size() , c = grid[0].size() ;\n r /= 2 ;\n c /= 2 ;\n long long ans = 0 ;\n for(int i = 0 ; i <= r - 1 ; i++){\n for(... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int f(vector<vector<int>> &v, int n, int m)\n {\n int ans=0;\n for(int i=0; i<n/2; i++)\n {\n for(int j=0; j<m/2; j++)\n {\n vector<int> count(2, 0);\n count[v[i][j]]++;\n count[v[i][m-... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int ans = 0 , n = grid.size() , m = grid[0].size() , cnt1 = 0 , cnt2 = 0 , total = 0 ;\n \n for( auto x : grid ){\n for( auto y : x ){\n total += y ;\n }\n }\n ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int n(grid.size()), m(grid[0].size()), res(0);\n for (int i(0); i < n/2; ++i) {\n for (int j(0); j < m/2; ++j) {\n int cnt(grid[i][j]);\n for (auto& [r,c] : vector<pair<int,int>... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int one_zero = 0;\n int double_one = 0;\n int n = grid.size();\n int m = grid[0].size();\n int ans = 0;\n\n for(int i = 0; i < (n + 1) / 2; i++) {\n for(int j = 0; j < (m + 1) / 2... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int n =grid.size(), m=grid[0].size();\n int a = (n)/2, b = (m)/2;\n if(n==1&&m==1) return grid[0][0];\n if(n==1){\n vector<vector<int>>dp1(b,vector<int>(2,INT_MAX));\n for(int i=... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "#define MOD 1000000007\n#define INF INT_MAX\n#define endl \"\\n\"\n#define pb push_back\n#define ppb pop_back\n#define ff first\n#define ss second\n#define sz(x) ((int)(x).size())\n#define all(x) (x).begin(), (x).end()\n\nclass Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n \n int ans=0;\n \n bool check(int x, int y){\n return x==y;\n }\n \n pair<int,int> util(vector<int>v){\n \n int n=v.size(), t=0, cnt=0;\n for(int j=0;j<n/2;j++){\n bool c1 = check(v[j],v[n-j-1]);\n if(c1) t+=... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n pair<int,int> util(vector<int>v){\n int n=v.size(), t=0, cnt=0;\n for(int j=0;j<n/2;j++){\n bool c1 = v[j]==v[n-j-1];\n if(c1) t+=v[j]; \n else cnt++;\n }\n return {t,cnt};\n }\n \n int minFlips(vector<vect... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int ans = 0;\n int m = grid.size();\n int n = grid[0].size();\n int cnt0 = 0;\n int cnt1 = 0;\n vector<vector<bool>> vis(m, vector<bool>(n));\n\n for(int i = 0; i < m /2; ++i){\n ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(const vector<vector<int>>& grid) {\n // flip any cell\n // total number of 1's divisible by 4 if corners flip to 1 or none\n // rows and col palindromic = 4 headers, ifany are different, calculate min change\n \n // min needed? ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int nor = grid.size(), noc = grid[0].size();\n vector<vector<bool>> vis(nor, vector<bool>(noc, false));\n int startRow = 0, endRow = nor - 1;\n \n int totalCnt1 = 0;\n int startCol = 0, endC... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "using ll = long long;\nusing vi = vector<ll>;\nusing vvi = vector<vi>;\nusing pii = pair<ll,ll>;\nusing vp = vector<pii>;\nusing ti3 = tuple<ll,ll,ll>;\nusing vti3 = vector<ti3>;\nusing vs = vector<string>;\n\ntemplate<typename T>\nusing min_pq = priority_queue<T, vector<T>, greater<T>>;\ntemplate<typename... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int flips = 0;\n\n int r = grid.size(), c = grid[0].size();\n\n\n unordered_map<int,int> mp;\n if(r > 1 && c > 1){\n for(int i = 0; i <= (r-2)/2; i++){\n for(int j = 0; j <= (c-2... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int n = grid.size(), m = grid[0].size();\n int ans = 0;\n if((n & 1) && (m & 1)){\n ans += grid[n / 2][m / 2];\n grid[n / 2][m / 2] = 0;\n }\n //\n bool can = 0;\n ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n pair<int,int> find(vector<int>&v){\n int n=v.size();\n int cnt=0;\n int sum=0;\n for(int i=0;i<n/2;++i){\n if(v[i]==0 && v[n-1-i]==0)continue;\n else if(v[i]!=v[n-1-i])++cnt;\n else {\n sum+=2;\n ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "typedef long long int ll;\n\n\nclass Solution {\npublic:\n int minFlips(vector<vector<int>>& arr) {\n \n vector<ll> curr( 4, 1e6);\n curr[0] = 0;\n \n ll n = arr.size();\n ll m = arr[0].size();\n \n for( ll ci=0, cj=m-1; ci<=cj; ci++, cj--) {\n ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& a) {\n int n=a.size();\n int m=a[0].size();\n map<int,vector<int>>mp;\n vector<vector<bool>>vis(n,vector<bool>(m));\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){\n if(!vis[i][j]){... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int rec(int ind,int rem,vector<pair<int,int>>&cnt,vector<vector<int>>&dp){\n if(ind==cnt.size() && rem==0) return 0;\n if(ind==cnt.size() && rem!=0) return 1e9;\n if(dp[ind][rem]!=-1) return dp[ind][rem];\n \n int tempans=cnt[ind].first+rec(... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "#include <bits/stdc++.h>\n#include <vector>\nusing namespace std;\n#define ll long long\n#define ld long double\n#define each(i, a) for (auto &i : a)\n#define all(x) (x).begin(), (x).end()\n#define cmin(a, b) a = min(a, b)\n#define cmax(a, b) b = max(a, b)\ntemplate<typename T> using matrix = vector< vecto... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& a) \n {\n int n = a.size(),m = a[0].size(),i,j,cnt,sum,ans=0;\n unordered_map<int,vector<int>> mp;\n vector<vector<int>> vis(n,vector<int>(m));\n for(i=0;i<n;i++)\n {\n for(j=0;j<m;j++)\n ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int ans = 0;\n int n = (int)grid.size(), m = (int)grid[0].size();\n auto& a = grid;\n for (int i = 0; i < n / 2; i++) {\n for (int j = 0; j < m / 2; j++) {\n vector<int> h = {a[i... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n vector<vector<array<int,2>>> v(n, vector<array<int,2>>(m, {0, 0}));\n for(int i = 0; i < n; i++){\n for(int j = 0; j < m; j++){\n ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int n = grid.size(), m = grid[0].size(); \n int ans = 0; \n double x = 2.5;\n \n if (n % 2 == 1 && m % 2 == 1) {\n if (grid[n / 2][m / 2] == 1) {\n ans += 1; \n ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n\n int rec(int level,int cnt1,vector<int>&nums,vector<vector<int>>&dp){//minimum number of flips such that it becomes a palindrome and number of 1's is divisible by 4\n //pruning\n //base case\n if(level==nums.size()/2){\n if(cnt1==0) return 0;\n else re... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int flips = 0;\n int n = grid.size(), m = grid[0].size();\n vector<vector<int>> newGrid(n, vector<int>(m, 0));\n\n for (int i = 0; i < n; i++)\n for (int j = 0; j < m; j++)\n if ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "int64_t dp[2][4];\n\nclass Solution {\npublic:\n int minFlips(vector<vector<int>>& a) {\n const int n = (int)a.size(), m = (int)a[0].size();\n \n vector<pair<int, int>> tot;\n vector<vector<int>> vis(n, vector<int>(m, -1));\n // cout << \"n = \" << n << \", m = \" << m... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n vector<vector<int>> matrix = grid;\n int rowCount = matrix.size();\n int colCount = matrix[0].size();\n int totalFlips = 0;\n for(int r = 0; r<rowCount / 2; r++){\n for(int c = 0; c<colC... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int n=grid.size();\n int m=grid[0].size();\n int count=0;\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){\n if(grid[i][j]==1)\n count++;\n }\n }\... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>&grid){\n int n=grid.size();\n int m=grid[0].size();\n \n vector<vector<int>>vis(n,vector<int>(m,1));\n \n vector<pair<int,int>>vp;\n for(int i=0; i<=n/2; i++){\n for(int j=0; j<=m/2; ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n int c = 0;\n int d = m-1;\n int ans =0;\n int ones =0;\n int diffs =0;\n int bothzero = 0;\n int mid = 0;\n \n ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n int c = 0;\n int d = m-1;\n int ans =0;\n int ones =0;\n int diffs =0;\n int mid = 0;\n \n while(d>=c){\n ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n vector<vector<int>> grid2 = grid;\n int rSize = grid.size(), cSize = grid[0].size();\n int sum = 0;\n for (auto row: grid)\n sum = accumulate(row.begin(), row.end(), sum);\n int flips = ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int n = grid.size(), m = grid[0].size();\n vector<vector<int>> tmp = grid;\n int ans = 0;\n for(int i = 0; i < (n + 1) / 2; i++) {\n for(int j = 0; j < (m + 1) / 2; j++) {\n if(i... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n \n int ans =0;\n \n for(int i= 0 ;i<n/2 ;i++){\n for(int j= 0 ;j<m/2 ;j++){\n map<int,int>mp;\n int ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int m = grid.size(), n = grid[0].size();\n int cnt = 0;\n // if(m==1){\n // int cnt1 = 0;\n // for(int i=0; i<n; i++){\n // if(grid[0][i]==1)\n // cnt1++;\... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int ans=0;\n int n=grid.size(), m=grid[0].size();\n vector<vector<int>> ok=grid; int p=0;\n for (int i=0;i<((n/2)+(n%2));i++){\n for (int j=0;j<((m/2)+(m%2));j++){\n vector<int> ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& a) {\n int i,j;\n int n=a.size();\n int m=a[0].size();\n int ans=0;\n for(i=0;i<n/2;i++){\n for(j=0;j<m/2;j++){\n map<int,int>mp;\n mp[a[i][j]]++;\n mp... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n\n int minFlips(vector<vector<int>>& grid) {\n int m=grid.size();\n int n=grid[0].size() ;\n int ans=0;\n map<pair<int,int>,bool>visitedpair;\n for(int i=0;i<m/2;i++){\n \n for(int j=0;j<n/2;j++){\n int co... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "#include <bits/stdc++.h>\n\nusing namespace std;\n\ntemplate<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << \", \" << p.second << ')'; }\ntemplate<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, type... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "#define pii pair<int,int>\nclass Solution {\npublic:\n pair<int,int> f(vector<int>&v){\n int i=0, j = v.size()-1;\n int c = 0;\n while(i<=j){\n if(v[i]!=v[j]) {\n c++;\n }\n i++;\n j--;\n }\n int ans = 0;\n ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) {\n int n = grid.size() , m = grid[0].size();\n int ans = 0;\n for(int i = 0 ; i < n / 2 ; i++){\n for(int j = 0 ; j < m / 2 ; j++){\n map<int,int>mp;\n mp[grid[i][j]]++;\n ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& V) {\n int l = V.size();\n int b = V[0].size();\n if (l == 1 && b == 1) {\n if (V[0][0] == 1) {\n return 1;\n } else {\n return 0;\n }\n }\n vec... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\n\n vector<vector<int>> dp;\n\n int findMin(int i, int sum, vector<pair<int,int>> &v) {\n if(i == v.size()) {\n return sum == 0 ? 0 : 1e9;\n }\n\n if(dp[i][sum] != -1) return dp[i][sum];\n\n // convert to 0's\n int zeros = findMin(i+1, su... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\n\n vector<vector<int>> dp;\n\n int findMin(int i, int sum, vector<pair<int,int>> &v) {\n if(i == v.size()) {\n return sum == 0 ? 0 : 1e9;\n }\n\n if(dp[i][sum] != -1) return dp[i][sum];\n\n // convert to 0's\n int zeros = findMin(i+1, su... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) \n {\n int m=grid.size(),n=grid[0].size(),ans=0;\n vector<vector<int>>v0(m,vector<int>(n,0)),v1(m,vector<int>(n,0));\n for(int i=0;i<((m)/2);i++)\n {\n for(int j=0;j<((n)/2);j++)\n ... |
3,524 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>
<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>
<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code... | 3 | {
"code": "class Solution {\npublic:\n int minFlips(vector<vector<int>>& grid) \n {\n int m=grid.size(),n=grid[0].size(),ans=0;\n vector<vector<int>>v0(m,vector<int>(n,0)),v1(m,vector<int>(n,0));\n for(int i=0;i<((m)/2);i++)\n {\n for(int j=0;j<((n)/2);j++)\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.