id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
376 | <p>A <strong>wiggle sequence</strong> is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with one element and a sequence with two non-equal elements are trivially wiggle sequ... | 3 | {
"code": "class Solution {\npublic:\n int solve(int i, int prev, int prevSign, vector<int>& nums, vector<vector<vector<int>>>& dp) {\n if (i == nums.size()) return 0;\n int take = 0;\n if (dp[i][prev][prevSign] != -1) return dp[i][prev][prevSign];\n int notTake = solve(i+1, prev, prevS... |
376 | <p>A <strong>wiggle sequence</strong> is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with one element and a sequence with two non-equal elements are trivially wiggle sequ... | 3 | {
"code": "class Solution {\npublic:\n int solve(vector<int>&nums,int i,int j,bool flag,vector<vector<vector<int>>> &dp ){\n if(i>=nums.size()){\n return 0;\n }\n if(dp[i][j][flag]!=-1){\n return dp[i][j][flag];\n }\n if(flag){\n int inc=INT_MIN;\... |
376 | <p>A <strong>wiggle sequence</strong> is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with one element and a sequence with two non-equal elements are trivially wiggle sequ... | 3 | {
"code": "class Solution {\npublic:\n int findLWS(int i,int iprev,int f,vector<int>& nums,vector<vector<vector<int>>>& dp){\n if(i>=nums.size()) return 1;\n int fInd=f;\n if(f==-1) fInd=2;\n \n if(dp[i][iprev][fInd]!=-1) return dp[i][iprev][fInd];\n \n int diff=num... |
376 | <p>A <strong>wiggle sequence</strong> is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with one element and a sequence with two non-equal elements are trivially wiggle sequ... | 3 | {
"code": "class Solution {\npublic:\n int fdp(int i, int prev, int x, vector<vector<vector<int>>> &dp, vector<int>& nums){\n if (i==nums.size()){\n return 0;\n }\n \n if (dp[i][prev+1][x]!=-1) return dp[i][prev+1][x];\n \n int np= 0+ fdp(i+1, prev, x, dp, nums)... |
376 | <p>A <strong>wiggle sequence</strong> is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with one element and a sequence with two non-equal elements are trivially wiggle sequ... | 3 | {
"code": "class Solution {\npublic:\n int solve(vector<int> &nums, int i, int prev, int sign, vector<vector<vector<int>>> &dp){\n if(i==nums.size()) return 0;\n if(dp[i][prev+1][sign]!=-1) return dp[i][prev+1][sign];\n int ans = 0;\n if(prev==-1){\n ans=max(ans,1+solve(nums,... |
376 | <p>A <strong>wiggle sequence</strong> is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with one element and a sequence with two non-equal elements are trivially wiggle sequ... | 3 | {
"code": "class Solution {\npublic:\n int solve(vector<int>&nums,int index,int prev,int sign,vector<vector<vector<int>>>&dp){\n if(index == nums.size()){\n return 0;\n }\n\n if(dp[index][prev+1][sign+1] != -1){\n return dp[index][prev+1][sign+1];\n }\n\n in... |
376 | <p>A <strong>wiggle sequence</strong> is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with one element and a sequence with two non-equal elements are trivially wiggle sequ... | 3 | {
"code": "class Solution {\npublic:\n int solve(int ind, int prev, vector<int>& nums, vector<vector<vector<int>>>& dp, bool flag) {\n if (ind >= nums.size()) {\n return 0;\n }\n\n if (dp[ind][prev + 1][flag] != -1) {\n return dp[ind][prev + 1][flag];\n }\n\n ... |
376 | <p>A <strong>wiggle sequence</strong> is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with one element and a sequence with two non-equal elements are trivially wiggle sequ... | 3 | {
"code": "class Solution {\npublic:\n \n int func(int i, int prev, int flag, vector<int>&nums, vector<vector<vector<int>>>&dp) {\n \n if(i == nums.size())\n return 0;\n \n if(dp[i][prev + 1][flag] != -1) \n return dp[i][prev + 1][flag];\n\n int p1 = 0, p2 = 0, p3 = 0;\n // taken;\n /... |
376 | <p>A <strong>wiggle sequence</strong> is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with one element and a sequence with two non-equal elements are trivially wiggle sequ... | 3 | {
"code": "class Solution {\npublic:\n \n int maxwiggle( int i, int prev, bool ispos, vector<int>& nums, int n, vector<vector<vector<int>>>& dp) {\n \n // base case\n if ( i==n ) {\n return 0;\n }\n \n // rec case\n if ( dp[i][prev+1][ispos] != -1 ) {\n ... |
2,432 | <p>Given an integer array <code>nums</code>, return <em>the number of <strong>subarrays</strong> filled with </em><code>0</code>.</p>
<p>A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input... | 0 | {
"code": "class Solution {\npublic:\n long long zeroFilledSubarray(vector<int>& nums) {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n unordered_map<long long,long long> mp;\n long long len = nums.size();\n long long ct = 0;\n long long ans = 0;\n for(int i =... |
2,432 | <p>Given an integer array <code>nums</code>, return <em>the number of <strong>subarrays</strong> filled with </em><code>0</code>.</p>
<p>A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input... | 0 | {
"code": "auto init = []()\n{ \n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n return 'c';\n}();\nclass Solution {\npublic:\n long long zeroFilledSubarray(vector<int>& nums) {\n long long ans = 0;\n int left = -1;\n const int n = nums.size();\n\n for (int i = 0;i ... |
2,432 | <p>Given an integer array <code>nums</code>, return <em>the number of <strong>subarrays</strong> filled with </em><code>0</code>.</p>
<p>A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input... | 0 | {
"code": "class Solution {\npublic:\n long long zeroFilledSubarray(vector<int>& nums) {\n long long int ans=0LL;\n ios_base::sync_with_stdio(0);\n int n = nums.size();\n int count=0;\n for(auto &x:nums)\n {\n if(x==0){\n ++count;\n ... |
2,432 | <p>Given an integer array <code>nums</code>, return <em>the number of <strong>subarrays</strong> filled with </em><code>0</code>.</p>
<p>A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input... | 0 | {
"code": "class Solution {\npublic:\n long long zeroFilledSubarray(vector<int>& nums) {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n \n long long ans = 0;\n long long temp = 0, n = nums.size();\n\n for (int i = 0; i < n; i++)\n {\n if (nums[i] ==... |
2,432 | <p>Given an integer array <code>nums</code>, return <em>the number of <strong>subarrays</strong> filled with </em><code>0</code>.</p>
<p>A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input... | 0 | {
"code": "class Solution {\npublic:\n//initial solution\n long long zeroFilledSubarray(vector<int>& nums) {\n ios_base::sync_with_stdio(0);\n\n map<long long ,long long> mpp;\n int r=0;\n int n = nums.size();\n int l=-1;\n int cnt=0;\n int z=0;\n wh... |
2,432 | <p>Given an integer array <code>nums</code>, return <em>the number of <strong>subarrays</strong> filled with </em><code>0</code>.</p>
<p>A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input... | 0 | {
"code": "class Solution {\npublic:\n long long zeroFilledSubarray(vector<int>& nums) {\n long long count=0;\n long zeros=0;\n int n=nums.size();\n for(int i=0;i<n;i++)\n {\n if(nums[i]==0)\n {\n zeros++;\n \n \n... |
2,432 | <p>Given an integer array <code>nums</code>, return <em>the number of <strong>subarrays</strong> filled with </em><code>0</code>.</p>
<p>A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input... | 0 | {
"code": "class Solution {\npublic:\n long long zeroFilledSubarray(vector<int>& nums) {\n long long count = 0;\n for (int i = 0, j = 0; i < nums.size(); i = j) {\n j = i;\n while (j < nums.size() && nums[i] == nums[j]) j++;\n if (nums[i] == 0) count += 1LL * (j - i) ... |
2,432 | <p>Given an integer array <code>nums</code>, return <em>the number of <strong>subarrays</strong> filled with </em><code>0</code>.</p>
<p>A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input... | 0 | {
"code": "class Solution {\npublic:\n long long zeroFilledSubarray(vector<int>& nums) {\n long long ans = 0, value = 1;\n for(int head = 0;head<nums.size();head++)\n {\n if(nums[head]==0)\n {\n ans+=value;\n value+=1;\n }\n ... |
2,432 | <p>Given an integer array <code>nums</code>, return <em>the number of <strong>subarrays</strong> filled with </em><code>0</code>.</p>
<p>A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input... | 0 | {
"code": "class Solution {\n public:\n long long zeroFilledSubarray(vector<int>& nums) {\n long ans = 0;\n int indexBeforeZero = -1;\n\n for (int i = 0; i < nums.size(); ++i)\n if (nums[i])\n indexBeforeZero = i;\n else\n ans += i - indexBeforeZero;\n\n return ans;\n }\n};",
"... |
2,432 | <p>Given an integer array <code>nums</code>, return <em>the number of <strong>subarrays</strong> filled with </em><code>0</code>.</p>
<p>A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input... | 1 | {
"code": "class Solution {\npublic:\n long long zeroFilledSubarray(vector<int>& s) {\n int i=0,j=0;\n long long int c=0;\n while(j<s.size()){\n if(s[j]==0){\n while(j<s.size()&&s[j]==0){\n j++;\n }\n long long int x=j-... |
2,432 | <p>Given an integer array <code>nums</code>, return <em>the number of <strong>subarrays</strong> filled with </em><code>0</code>.</p>
<p>A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input... | 3 | {
"code": "class Solution {\npublic:\n long long zeroFilledSubarray(vector<int>& nums) {\n long long count=0;\n int i=0,j=0;\n int n=nums.size();\n\n while(j<n){\n if(nums[j]!=0){\n count+=(long)(j-i)*(j-i+1)/2;\n j++;\n i=j;\n ... |
2,432 | <p>Given an integer array <code>nums</code>, return <em>the number of <strong>subarrays</strong> filled with </em><code>0</code>.</p>
<p>A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input... | 3 | {
"code": "class Solution {\nprivate:\n long long backtrack(vector<int>& nums, int startIdx, int currIdx) {\n if (currIdx >= nums.size()) {\n return 0;\n } else if (nums[currIdx] != 0) {\n return 0;\n } else {\n return 1 + backtrack(nums, startIdx, currIdx+1);\... |
2,432 | <p>Given an integer array <code>nums</code>, return <em>the number of <strong>subarrays</strong> filled with </em><code>0</code>.</p>
<p>A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input... | 3 | {
"code": "class Solution {\npublic:\n long long zeroFilledSubarray(vector<int>& nums) {\n vector<int> counts;\n int n=nums.size();\n long long totalCount=0;\n for(int i=0;i<n;i++){\n int cnt=0;\n while(i<n && nums[i]==0){\n cnt++;\n i... |
2,432 | <p>Given an integer array <code>nums</code>, return <em>the number of <strong>subarrays</strong> filled with </em><code>0</code>.</p>
<p>A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input... | 3 | {
"code": "class Solution {\npublic:\n long long zeroFilledSubarray(vector<int>& nums) {\n long long ans =0;\n vector<int> v;\n int cnt =0;\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]==0)cnt++;\n else\n {\n if(cnt==0)continue;... |
2,432 | <p>Given an integer array <code>nums</code>, return <em>the number of <strong>subarrays</strong> filled with </em><code>0</code>.</p>
<p>A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input... | 3 | {
"code": "class Solution {\npublic:\n long long zeroFilledSubarray(vector<int>& nums) {\n long long ans =0;\n int currentCount = 0;\n unordered_map<int, int> mp;\n for(int i=0; i<nums.size(); i++){\n if (nums[i] ==0){\n currentCount++;\n }\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 0 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int count = 0;\n int n = grid.size();\n for(int i = 0; i < n; i++){\n for(int c = 0; c < n; c++){\n int flag = 1;\n for(int j = 0; j < n; j++){\n if(... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 0 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int n = grid.size();\n int ans = 0;\n for(int i=0; i<n; i++){\n for(int j=0; j<n; j++){\n bool match = true;\n for(int k=0; k<n; k++){\n if(grid[i][k... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 0 | {
"code": "class Solution {\nprivate:\n static constexpr int BUCKET_COUNT = 50;\n struct VectorHash {\n size_t operator()(const vector<int>& v) const {\n int sum = accumulate(v.begin(), v.end(), 0);\n return sum % BUCKET_COUNT;\n }\n };\npublic:\n int equalPairs(vector<... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 0 | {
"code": "class Solution {\n\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n ios_base::sync_with_stdio(0);\n\n map<vector<int>, int> map;\n\n int res = 0;\n\n for (auto a : grid) {\n if (map.find(a) == map.end())\n map.insert({a, 1});\n els... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 1 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n vector<vector<int>> rows = grid;\n vector<vector<int>> columns (size(grid), vector<int>(size(grid)));\n map <vector<int>, int> rowsmap;\n map <vector<int>, int> columnsmap;\n for (int i = 0; i < ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 1 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int pairs = 0;\n unordered_map<string, int> rowset;\n unordered_map<string, int> colset;\n\n string buffer = \"\";\n\n for (auto row : grid) {\n\n buffer = \"\";\n for (auto... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 2 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int n = grid.size();\n int count = 0;\n\n set<vector<int>> unique;\n unordered_map<int, vector<int>> duplicate;\n\n for (int i = 0; i < n; ++i) {\n vector<int> curr = grid[i];\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 2 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int n = grid.size();\n int count = 0;\n\n set<vector<int>> unique;\n unordered_map<int, vector<int>> duplicate;\n\n for (int i = 0; i < n; ++i) {\n vector<int> curr = grid[i];\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n map<vector<int>,int> mp;\n map<vector<int>,int> mp1;\n for(int i=0;i<grid.size();i++){\n vector<int> store;\n vector<int> store2;\n for(int j=0;j<grid.size();j++){\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n map<vector<int>, int> rows;\n for (int i = 0; i < grid.size(); i++) {\n vector<int> vec;\n for (int j = 0; j < grid[0].size(); j++) {\n vec.push_back(grid[i][j]);\n }\n... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n const int n_rows = grid.size();\n const int n_cols = grid[0].size();\n\n vector<string> rows(n_rows);\n vector<string> cols(n_cols);\n\n for (int i = 0; i < n_rows; i++) {\n for (int j... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n\n string createHash(vector<vector<int>>&grid,int i,bool isRowWise){\n string hash=\"\";\n if(isRowWise){\n for(int j=0; j<grid[0].size();j++){\n hash+= std::to_string(grid[i][j]) +\"_\";\n }\n }else{\n for(i... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int n = grid.size(), m = grid[0].size();\n map<string, int> mp;\n vector<string> r, c;\n for (int i = 0; i < n; i++) {\n string row = \"\", col = \"\";\n for (int j = 0; j < m; j++... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid){\n vector<string>row;\n for(int i=0; i<grid.size() ; i++){\n string x=\"\";\n for(int j=0 ; j<grid[0].size(); j++){\n x+=to_string(grid[i][j]);\n x+=' ';\n }... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) \n {\n map<string, int> rows;\n int n = grid.size();\n\n for(vector<int>& row : grid)\n {\n string code = encode(row);\n rows[code]++;\n }\n\n int ctr = 0;\n fo... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n vector<string> horizontal;\n vector<string> vertical;\n for (int i = 0; i < grid[0].size(); i++) {\n string sum1 = \"\";\n string sum2 = \"\";\n for(int j = 0; j < grid.size();... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int n=grid.size(),ans=0;\n vector<string>colGrid,rowGrid;\n unordered_map<string,int>rowMap,colMap;\n\n for(int j=0;j<n;j++){\n string temp=\"\";\n for(int i=0;i<n;i++){\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n std::hash<std::string> hashFunction; // Create a hash function object for strings\n auto hashFn = [=](const vector<int>& input)\n {\n string s;\n for(const int i : input)\n {\... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int n=grid.size();\n int ans=0;\n unordered_map<int, set<pair<int,int>>>m;\n\n for(int i=0;i<n;i++){\n for(int j=0;j<n;j++){\n m[grid[i][j]].insert({i,j});\n }\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n\n string convertToKey(vector<int> nums) {\n\n string result;\n for(int num : nums) {\n result += to_string(num) + \",\";\n }\n return result;\n }\n\n\n int equalPairs(vector<vector<int>>& grid) {\n unordered_map<string, int>... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\n class Trie {\n unordered_map<int, Trie> mp;\n int count = 0;\n public:\n void insert(vector<vector<int>> &g, int row, int col = 0) {\n if (col == g.size()) ++count;\n else {\n mp[g[row][col]].insert(g, row, col + 1);\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n struct NumTrie\n {\n std::unordered_map<int, NumTrie *> next;\n int cnt = 0;\n };\n\n int Insert(std::vector<std::vector<int> > &grid, NumTrie *trie, int r, int c, int row)\n {\n NumTrie *t = trie;\n for (; std::max(r, c) < grid.size();... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n struct node {\n int val;\n int count;\n unordered_map<int, struct node*> children;\n node(int v) {\n val = v;\n count = 0;\n }\n void addChildren(struct node* child) {\n children[child->val] = child;\n... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\n struct trie {\n unordered_map<int, trie*> children;\n int count;\n trie() {\n count = 0;\n }\n };\n void insert(trie* root, vector<int>& v) {\n for(int n: v) {\n if (root->children.find(n) == root->children.end()) {\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class TrieNode {\npublic:\n unordered_map<int, TrieNode*> children;\n int count;\n\n TrieNode(): count(0) {}\n};\n\nclass Trie {\n TrieNode* root;\npublic:\n Trie() {\n root = new TrieNode();\n }\n\n void insert(vector<int>& nums) {\n TrieNode* node = root;\n for (i... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "struct Trie {\n struct TrieNode {\n std::unordered_map<int, std::pair<std::unique_ptr<TrieNode>, int>> children{};\n };\n std::unique_ptr<TrieNode> root;\n\n Trie() : root{std::make_unique<TrieNode>()} {};\n \n void insert(const std::vector<int>& numbers) {\n if (numbers.emp... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class TrieNode {\npublic:\n int num;\n unordered_map<int, TrieNode*> children;\n TrieNode() : num(0) {}\n};\n\nclass Trie {\npublic:\n TrieNode* trie;\n\n Trie() {\n trie = new TrieNode();\n }\n\n void insert(vector<int>& arr) {\n TrieNode* myTrie = trie;\n for(int... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Trie {\npublic:\n int count;\n unordered_map<int, Trie*> children;\n};\n\nclass Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n Trie* t = new Trie();\n \n for (auto row: grid) {\n auto curT = t;\n for (int n: row) {\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class TrieNode {\n public:\n TrieNode() {}\n\n int count = 0;\n std::unordered_map<int, TrieNode> children;\n};\n\nclass Trie {\n public:\n TrieNode* trie;\n\n Trie() {\n trie = new TrieNode();\n }\n\n ~Trie() {\n delete trie;\n trie = nullptr;\n }\n\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int n = grid.size();\n vector<unordered_map<int, int>> trie(1, unordered_map<int, int>());\n vector<int> count(1, 0);\n for(int i = 0; i < n; i++) {\n int node = 0;\n for(int j = 0... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n map<vector<int>, int> mp1, mp2;\n int n = grid.size();\n for(int i=0; i<n; i++){\n mp1[grid[i]]++;\n }\n\n for(int j=0; j<n; j++){\n vector<int> temp;\n for(int i... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int n=grid.size();\n map<vector<int>,int> mp1;\n map<vector<int>, int> mp2;\n for(int i=0;i<n;i++){\n mp1[grid[i]]++;\n }\n for(int i=0;i<n;i++){\n vector<int> arr;\n... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int n=grid.size();\n map<vector<int>,int> mpp1,mpp2;\n for(int i=0;i<n;i++){\n vector<int> v(grid[i].begin(),grid[i].end());\n mpp1[v]++;\n }\n for(int i=0;i<n;i++){\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n map<vector<int>, int> r; // string key ex: \"321\", frequency of key value ex: 2\n map<vector<int>, int> c; // ex: \"312\" 1\n int pairs = 0;\n\n for (int i = 0; i < grid.size(); i++) { // which row \n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) \n {\n // set<vector<int>> rowset;\n // set<vector<int>> colset;\n\n map<vector<int>,int> rowmap;\n map<vector<int>,int> colmap;\n\n for(int i=0;i<grid.size();i++)\n {\n vector<int... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n map<vector<int>,int>row,col;\n for(int i=0;i<grid.size();i++){\n vector<int>rowv;\n vector<int>colv;\n for(int j=0;j<grid.size();j++){\n rowv.push_back(grid[i][j]);\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int count=0;\n map <vector<int>,int> x;\n for(int i=0;i<grid.size();i++){\n vector<int> v;\n for(int j=0;j<grid.size();j++){\n v.push_back(grid[i][j]);\n x[v... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n unordered_map<string, int> col, row;\n int counter = 0;\n \n for (int i = 0; i < grid.size(); ++i) {\n string r;\n string c;\n for (int j = 0; j < grid.size(); ++j) {\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n map<string, int> row, col;\n int ans= 0;\n for(int i=0; i<grid[0].size(); ++i){\n string temp= \"\", temp1= \"\";\n for(int j=0; j<grid[0].size(); ++j){\n temp+= to_string(... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int n=grid.size();\n int m=grid[0].size();\n int ans=0;\n vector<string> row(n),col(m);\n unordered_map<string,int> rowmp, colmp;\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\n struct Trie {\n struct TrieNode {\n unordered_map<int, unique_ptr<TrieNode>> children;\n int counts = 0;\n };\n\n TrieNode root;\n\n void insert(const vector<int>& nums) {\n auto node = &root;\n for (auto num : nu... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int ans=0;\n map<vector<int>,int>mp;\n vector<int>arr;\n int n=grid.size();\n for(int i=0;i<n;i++){\n for(int j=0;j<n;j++){\n arr.push_back(grid[i][j]);\n}\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int ans=0;\n map<vector<int>,int>mp;\n vector<int>arr;\n int n=grid.size();\n for(int i=0;i<n;i++){\n for(int j=0;j<n;j++){\n arr.push_back(grid[i][j]);\n}\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "#pragma GCC optimize(\"O3\")\n#pragma GCC target(\"avx2, bmi, bmi2, lzcnt, popcnt\")\nstatic const bool __boost = [](){\n cin.tie(nullptr);\n cout.tie(nullptr);\n return ios_base::sync_with_stdio(false);\n}();\nclass Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n uno... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n set<vector<int>> res;\n unordered_map<int,vector<int>> mp;\n int counter=0;\n for(int i=0;i<grid.size();i++){\n if(res.find(grid[i])!=res.end()){\n mp[i]=grid[i];\n }\n res.insert(grid[i... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n set<vector<int>>st;\n unordered_map<int,vector<int>>mpp;\n int n=grid.size();\n int c=0;\n for(int i=0;i<n;i++){\n if(st.find(grid[i])!=st.end()){\n mpp[i]=grid[i];\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int count = 0;\n set<vector<int>> res;\n unordered_map<int, vector<int>> dupe;\n\n // push each column/ row into an unordered map\n for(int i = 0; i < grid.size(); i++){\n if(res.find(... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n set<vector<int>>st;\n unordered_map<int,vector<int>>duplicate;\n for(int i=0;i<grid.size();i++){\n if(st.find(grid[i])!=st.end()){\n duplicate[i]=grid[i];\n }\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int n = grid.size();\n int ans = 0;\n set<vector<int>> res;\n unordered_map<int, vector<int>> map;\n for(int i = 0; i<n; i++){\n if(res.find(grid[i])!=res.end()) map[i] = grid[i];\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n\n // int n = grid.size();\n // int ans{};\n // for(int i{}; i<n; i++) {\n // for(int j{}; j<n; j++) {\n // int cnt{};\n // for(int k{}; k<n; k++) {\n // ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int n=grid.size();\n unordered_map<int,vector<int>>mp;\n set<vector<int>>s;\n for(int i=0;i<n;i++){\n s.insert(grid[i]);\n mp[i]=grid[i];\n }\n int count=0;\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int n=grid.size();\n set<vector<int>>st;\n unordered_map<int,vector<int>>mp;\n for(int i=0;i<n;i++){\n mp[i]=grid[i];\n st.insert(grid[i]);\n }\n\n int count=0;\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int res = 0;\n for(int i = 0; i < grid[0].size(); i++)\n {\n for(auto row:grid)\n {\n for(int j = 0; j < grid.size(); j++)\n {\n if(grid[j... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int res = 0;\n for(int i = 0; i < grid[0].size(); i++)\n {\n for(auto row:grid)\n {\n for(int j = 0; j < grid.size(); j++)\n {\n if(grid[j... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int ans=0;\n vector<int>temp;\n for(int i=0;i<(int)grid.size();i++){\n for(int j=0;j<(int)grid.size();j++) temp.push_back(grid[j][i]);\n for(auto it:grid) if(it==temp) ans++;\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n \n std::vector<int> cur_col;\n int ans = 0;\n\n for(int i = 0; i < grid.size(); ++i){\n cur_col = {};\n for(int j = 0; j< grid.size(); ++j) cur_col.push_back(grid[j][i]);\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\nprivate:\n vector<int> getCol(vector<vector<int>>& grid, int n, int j) {\n vector<int> col(n);\n for (int i = 0; i < n; i++)\n col[i] = grid[i][j];\n return col;\n }\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int n = grid.size(... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int res=0;\n if(grid.size()==0) return 0;\n\n int n = grid.size();\n vector<vector<int>> colgrid (n, vector<int>(n,0));\n \n for(int i=0; i < n ; i++){\n for(int j = 0; j < n ; ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n vector<vector<int>>col;\n vector<int> temp;\n for(int j=0;j<grid.size();j++){\n for(auto i:grid){\n temp.push_back(i[j]);\n }\n col.push_back(temp);\n temp.clear();\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n map<int, vector<int>> hash;\n int pairs = 0;\n\n for (int i = 0; i < grid.size(); ++i)\n hash[i] = grid[i];\n\n vector<int> arr;\n\n for (int col = 0; col < grid.size(); ++col) {\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n int equalPairs(vector<vector<int>>& grid) {\n int n = grid.size();\n vector<vector<int>> cols(n, vector<int>(n));\n \n \n for (int i=0; i<n; i++) {\n for (int j=0; j<n; j++) {\n cols[j][i] = grid[i][j];\n ... |
2,428 | <p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p>
<p>A row and column pair is... | 3 | {
"code": "class Solution {\npublic:\n void rotate(vector<vector<int>> &matrix, int n) {\n int row = n;\n int col = n;\n\n for (int i=0; i<row; i++ ) {\n for(int j=0; j<=i; j++) {\n int temp = 0;\n temp = matrix[i][j];\n matrix[i][j] = ma... |
1,329 | <p>We have <code>n</code> chips, where the position of the <code>i<sup>th</sup></code> chip is <code>position[i]</code>.</p>
<p>We need to move all the chips to <strong>the same position</strong>. In one step, we can change the position of the <code>i<sup>th</sup></code> chip from <code>position[i]</code> to:</p>
<ul... | 0 | {
"code": "class Solution {\n public:\n int minCostToMoveChips(vector<int>& position) {\n vector<int> count(2);\n for (const int p : position)\n ++count[p % 2];\n return min(count[0], count[1]);\n }\n};",
"memory": "8900"
} |
1,329 | <p>We have <code>n</code> chips, where the position of the <code>i<sup>th</sup></code> chip is <code>position[i]</code>.</p>
<p>We need to move all the chips to <strong>the same position</strong>. In one step, we can change the position of the <code>i<sup>th</sup></code> chip from <code>position[i]</code> to:</p>
<ul... | 0 | {
"code": "class Solution {\npublic:\n int help(vector<int>&vec, int key)\n {\n int cnt = 0;\n for(auto val:vec)\n if(val%2 == key) cnt++;\n return cnt;\n }\n int minCostToMoveChips(vector<int>& position) {\n int ans1 = help(position, 0);\n int ans2 = help(positi... |
1,329 | <p>We have <code>n</code> chips, where the position of the <code>i<sup>th</sup></code> chip is <code>position[i]</code>.</p>
<p>We need to move all the chips to <strong>the same position</strong>. In one step, we can change the position of the <code>i<sup>th</sup></code> chip from <code>position[i]</code> to:</p>
<ul... | 0 | {
"code": "class Solution {\npublic:\n int minCostToMoveChips(vector<int>& position) {\n int even =0, odd=0;\n for(int i=0;i<position.size();i++){\n if(position[i]%2==0){\n even++;\n }\n else{\n odd++;\n }\n }\n ... |
1,329 | <p>We have <code>n</code> chips, where the position of the <code>i<sup>th</sup></code> chip is <code>position[i]</code>.</p>
<p>We need to move all the chips to <strong>the same position</strong>. In one step, we can change the position of the <code>i<sup>th</sup></code> chip from <code>position[i]</code> to:</p>
<ul... | 0 | {
"code": "class Solution {\npublic:\n int minCostToMoveChips(vector<int>& position) {\n int cnt[2]={};\n for(auto p:position)\n ++cnt[p%2];\n return min(cnt[0],cnt[1]);\n }\n};",
"memory": "9100"
} |
1,329 | <p>We have <code>n</code> chips, where the position of the <code>i<sup>th</sup></code> chip is <code>position[i]</code>.</p>
<p>We need to move all the chips to <strong>the same position</strong>. In one step, we can change the position of the <code>i<sup>th</sup></code> chip from <code>position[i]</code> to:</p>
<ul... | 1 | {
"code": "class Solution {\npublic:\n int minCostToMoveChips(vector<int>& position) {\n //[2,2,2,2,3,3,3,4,4,4,4,4,5,5,5]\n //2\n //2\n //[2,2,3,3,3]\n int n = position.size();\n int odd_count = 0;\n int even_count = 0;\n for(int i = 0; i < n; i++){\n ... |
1,329 | <p>We have <code>n</code> chips, where the position of the <code>i<sup>th</sup></code> chip is <code>position[i]</code>.</p>
<p>We need to move all the chips to <strong>the same position</strong>. In one step, we can change the position of the <code>i<sup>th</sup></code> chip from <code>position[i]</code> to:</p>
<ul... | 1 | {
"code": "class Solution {\npublic:\n int minCostToMoveChips(vector<int>& arr) {\n int even=0;\n int odd=0;\n for(int i=0;i<arr.size();i++){\n if(arr[i]%2 == 0){\n even=even+1;\n }\n else{\n odd = odd+1;\n }\n }\... |
1,330 | <p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p>
<p>A <strong>subsequence</strong>... | 0 | {
"code": "class Solution {\n int f[50000];\n int maxn=1;\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n int n=arr.size();\n //f[arr[0]+20000]=1;\n for(int i=0;i<n;i++){\n f[arr[i]+20000]=f[arr[i]+20000-difference]+1;\n if(maxn<f[arr[i]+2000... |
1,330 | <p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p>
<p>A <strong>subsequence</strong>... | 0 | {
"code": "class Solution1 {\npublic:\n int longestSubsequence(vector<int>& a, int d) {\n map<int,int> mp;\n int n = a.size();\n int mx = 1;\n for(int i=0; i<n; i++){\n int x = a[i]-d;\n if(mp.find(x) != mp.end()){\n mp[a[i]] = 1+mp[x];\n ... |
1,330 | <p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p>
<p>A <strong>subsequence</strong>... | 0 | {
"code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n int n = arr.size();\n if (n == 0) return 0;\n\n int minVal = *min_element(arr.begin(), arr.end());\n int maxVal = *max_element(arr.begin(), arr.end());\n \n vector<int> dp(m... |
1,330 | <p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p>
<p>A <strong>subsequence</strong>... | 0 | {
"code": "class Solution {\npublic:\n Solution() {\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(NULL);\n std::cout.tie(NULL);\n }\n\n int longestSubsequence(vector<int>& arr, int difference) {\n int dp[200001] = {0};\n int res = 0;\n for (int num : arr) {... |
1,330 | <p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p>
<p>A <strong>subsequence</strong>... | 0 | {
"code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int d) {\n int n=arr.size();\n int dp[200001];\n memset(dp,0,sizeof(dp));\n int ans=1;\n for(int i=0;i<n;i++){\n dp[arr[i]+10000]=1 + (arr[i]+10000-d>=0 ? dp[arr[i]+10000-d]:0);\n ... |
1,330 | <p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p>
<p>A <strong>subsequence</strong>... | 0 | {
"code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& a, int d) {\n \n \n vector<int> dp(20007,0);\n \n int ans=1;\n for(auto& x:a)\n {\n int index = x + 10000;\n int prev_index=index-d;\n if (prev_index >= 0 && ... |
1,330 | <p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p>
<p>A <strong>subsequence</strong>... | 0 | {
"code": "class Solution {\npublic:\n \n\nint longestSubsequence(vector<int>& arr, int difference) {\n vector<int> l(20001, 0);\n int maxim = 1;\n for (int i = 0; i < arr.size(); i++) {\n int cur = arr[i] + 10000;\n int s1 = 0;\n int s2 = 0;\n if (cur - difference >= 0 && cur ... |
1,330 | <p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p>
<p>A <strong>subsequence</strong>... | 0 | {
"code": "class Solution {\npublic:\n /*\n //TC=O(n^2)\n int longestSubsequence(vector<int>& arr, int difference) {\n int n = arr.size();\n vector<int> dp(n, 1);\n int ans=1;\n for(int i=1; i<n; i++){\n for(int j=i-1; j>=0; j--){\n if (arr[i]-arr[j] == d... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.