id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3,338 | <p>You are given a <strong>0-indexed</strong> integer matrix <code>grid</code> and an integer <code>k</code>.</p>
<p>Return <em>the <strong>number</strong> of <span data-keyword="submatrix">submatrices</span> that contain the top-left element of the</em> <code>grid</code>, <em>and have a sum less than or equal to </em... | 1 | {
"code": "class Solution {\npublic:\n int countSubmatrices(vector<vector<int>>& grid, int k) {\n if (grid[0][0] > k)\n return 0;\n int result = 0, row = 0;\n vector<int> sumRecord(grid[0].size(), 0);\n while (row < grid.size() && sumRecord.size() > 0) {\n int temp... |
3,338 | <p>You are given a <strong>0-indexed</strong> integer matrix <code>grid</code> and an integer <code>k</code>.</p>
<p>Return <em>the <strong>number</strong> of <span data-keyword="submatrix">submatrices</span> that contain the top-left element of the</em> <code>grid</code>, <em>and have a sum less than or equal to </em... | 1 | {
"code": "class Solution {\npublic:\n int countSubmatrices(vector<vector<int>>& grid, int k) {\n if (grid[0][0] > k)\n return 0;\n int result = 0, row = 0;\n vector<int> sumRecord(grid[0].size(), 0);\n while (row < grid.size() && sumRecord.size() > 0) {\n int temp... |
3,338 | <p>You are given a <strong>0-indexed</strong> integer matrix <code>grid</code> and an integer <code>k</code>.</p>
<p>Return <em>the <strong>number</strong> of <span data-keyword="submatrix">submatrices</span> that contain the top-left element of the</em> <code>grid</code>, <em>and have a sum less than or equal to </em... | 1 | {
"code": "class Solution {\npublic:\n int countSubmatrices(vector<vector<int>>& grid, int k) {\n //top left element should be present.. this is fixed\n //so variables are end row and end col \n //now sum<=k\n //there are n^2 different matrices possible \n //if we can find the su... |
3,338 | <p>You are given a <strong>0-indexed</strong> integer matrix <code>grid</code> and an integer <code>k</code>.</p>
<p>Return <em>the <strong>number</strong> of <span data-keyword="submatrix">submatrices</span> that contain the top-left element of the</em> <code>grid</code>, <em>and have a sum less than or equal to </em... | 1 | {
"code": "class Solution {\npublic:\n int countSubmatrices(vector<vector<int>>& grid, int k) {\n int n = grid.size(), m = grid[0].size();\n vector<int> prev(m,0), cur(m);\n if(grid[0][0] > k)return 0;\n int out = 0;\n for(int i = 0; i < n; ++i){\n cur[0] = grid[i][0] ... |
3,338 | <p>You are given a <strong>0-indexed</strong> integer matrix <code>grid</code> and an integer <code>k</code>.</p>
<p>Return <em>the <strong>number</strong> of <span data-keyword="submatrix">submatrices</span> that contain the top-left element of the</em> <code>grid</code>, <em>and have a sum less than or equal to </em... | 1 | {
"code": "class Solution {\npublic:\n int countSubmatrices(vector<vector<int>>& g, int k) \n {\n int v[1001]{};\n int out{};\n for(int i{}; i<size(g); ++i)\n for(int j{}, s{}; j<size(g[0]); ++j)\n v[j]+=g[i][j], s+=v[j], out+=s<=k;\n return out;\n }\n};"... |
3,338 | <p>You are given a <strong>0-indexed</strong> integer matrix <code>grid</code> and an integer <code>k</code>.</p>
<p>Return <em>the <strong>number</strong> of <span data-keyword="submatrix">submatrices</span> that contain the top-left element of the</em> <code>grid</code>, <em>and have a sum less than or equal to </em... | 1 | {
"code": "class Solution {\npublic:\n int countSubmatrices(vector<vector<int>>& grid, int k) {\n int m = grid.size(), n = grid[0].size();\n int s[m + 1][n + 1];\n memset(s, 0, sizeof(s));\n int ans = 0;\n for (int i = 1; i <= m; ++i) {\n for (int j = 1; j <= n; ++j) {... |
3,338 | <p>You are given a <strong>0-indexed</strong> integer matrix <code>grid</code> and an integer <code>k</code>.</p>
<p>Return <em>the <strong>number</strong> of <span data-keyword="submatrix">submatrices</span> that contain the top-left element of the</em> <code>grid</code>, <em>and have a sum less than or equal to </em... | 1 | {
"code": "class Solution {\npublic:\n int countSubmatrices(vector<vector<int>>& grid, int k) {\n int n = grid.size(), m = grid[0].size();\n int arr[n+1][m+1];\n for(int i = 0; i<=n; ++i){\n for(int j = 0; j<=m; ++j){\n arr[i][j] = 0;\n }\n }\n ... |
3,338 | <p>You are given a <strong>0-indexed</strong> integer matrix <code>grid</code> and an integer <code>k</code>.</p>
<p>Return <em>the <strong>number</strong> of <span data-keyword="submatrix">submatrices</span> that contain the top-left element of the</em> <code>grid</code>, <em>and have a sum less than or equal to </em... | 1 | {
"code": "class Solution {\npublic:\n int countSubmatrices(vector<vector<int>>& grid, int k) {\n \n int m = grid.size() ;\n int n = grid[0].size() ;\n \n int sum[m][n],count=0 ;\n \n for(int row=0;row<m;row++)\n {\n int currSum = 0 ;\n ... |
3,338 | <p>You are given a <strong>0-indexed</strong> integer matrix <code>grid</code> and an integer <code>k</code>.</p>
<p>Return <em>the <strong>number</strong> of <span data-keyword="submatrix">submatrices</span> that contain the top-left element of the</em> <code>grid</code>, <em>and have a sum less than or equal to </em... | 1 | {
"code": "class Solution \n{\npublic:\n int countSubmatrices(vector<vector<int>>& grid, int k) \n {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n\n int n = grid.size(), m = grid[0].size();\n vector<vector<int>> prefix = grid;\n for(int i = 0... |
3,338 | <p>You are given a <strong>0-indexed</strong> integer matrix <code>grid</code> and an integer <code>k</code>.</p>
<p>Return <em>the <strong>number</strong> of <span data-keyword="submatrix">submatrices</span> that contain the top-left element of the</em> <code>grid</code>, <em>and have a sum less than or equal to </em... | 1 | {
"code": "class Solution {\npublic:\n int countSubmatrices(vector<vector<int>>& a, int k) \n {\n int n=a.size();\n int m=a[0].size();\n if(a[0][0]>k)\n return 0;\n vector<vector<int>>dp(n,vector<int>(m,0));\n dp[0][0]=a[0][0];\n int ans=1;\n for(int i=1;i... |
3,338 | <p>You are given a <strong>0-indexed</strong> integer matrix <code>grid</code> and an integer <code>k</code>.</p>
<p>Return <em>the <strong>number</strong> of <span data-keyword="submatrix">submatrices</span> that contain the top-left element of the</em> <code>grid</code>, <em>and have a sum less than or equal to </em... | 1 | {
"code": "class Solution {\npublic:\n int countSubmatrices(vector<vector<int>>& grid, int k) {\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n \n int r=grid.size();\n int c=grid[0].size();\n vector<vector<int>> prefix(r,vector<int>(c,0));\n \n ... |
3,338 | <p>You are given a <strong>0-indexed</strong> integer matrix <code>grid</code> and an integer <code>k</code>.</p>
<p>Return <em>the <strong>number</strong> of <span data-keyword="submatrix">submatrices</span> that contain the top-left element of the</em> <code>grid</code>, <em>and have a sum less than or equal to </em... | 1 | {
"code": "class Solution {\npublic:\n int countSubmatrices(vector<vector<int>>& grid, int k) {\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n \n int r=grid.size();\n int c=grid[0].size();\n vector<vector<int>> prefix(r,vector<int>(c,0));\n \n ... |
3,338 | <p>You are given a <strong>0-indexed</strong> integer matrix <code>grid</code> and an integer <code>k</code>.</p>
<p>Return <em>the <strong>number</strong> of <span data-keyword="submatrix">submatrices</span> that contain the top-left element of the</em> <code>grid</code>, <em>and have a sum less than or equal to </em... | 1 | {
"code": "class Solution {\npublic:\n\n \n int countSubmatrices(vector<vector<int>>& grid, int k) \n {\n\n vector<vector<int>>sum;\n\n sum=grid;\n\n for(int i=0;i<grid.size();i++)\n {\n for(int j=0;j<grid[0].size();j++)\n {\n if(j>0)\n ... |
3,338 | <p>You are given a <strong>0-indexed</strong> integer matrix <code>grid</code> and an integer <code>k</code>.</p>
<p>Return <em>the <strong>number</strong> of <span data-keyword="submatrix">submatrices</span> that contain the top-left element of the</em> <code>grid</code>, <em>and have a sum less than or equal to </em... | 1 | {
"code": "class Solution {\npublic:\n int countSubmatrices(vector<vector<int>>& grid, int k) {\n int n = grid.size();\n int m = grid[0].size();\n vector<vector<int>> sum(n,vector<int>(m,0));\n sum[0][0] = grid[0][0];\n for(int j=1;j<m;j++){\n sum[0][j] = grid[0][j] + s... |
3,338 | <p>You are given a <strong>0-indexed</strong> integer matrix <code>grid</code> and an integer <code>k</code>.</p>
<p>Return <em>the <strong>number</strong> of <span data-keyword="submatrix">submatrices</span> that contain the top-left element of the</em> <code>grid</code>, <em>and have a sum less than or equal to </em... | 2 | {
"code": "class Solution {\npublic:\n int countSubmatrices(vector<vector<int>>& grid, int k) {\n int n=grid.size(), m=grid[0].size();\n vector<vector<int>> dp(n, vector<int> (m,0));\n int ans=0;\n for(int i=0; i<n; i++){\n for(int j=0; j<m; j++){\n if(i==0 && j==0){... |
3,338 | <p>You are given a <strong>0-indexed</strong> integer matrix <code>grid</code> and an integer <code>k</code>.</p>
<p>Return <em>the <strong>number</strong> of <span data-keyword="submatrix">submatrices</span> that contain the top-left element of the</em> <code>grid</code>, <em>and have a sum less than or equal to </em... | 2 | {
"code": "class Solution {\npublic:\n int countSubmatrices(vector<vector<int>>& grid, int k) {\n int n=grid.size(), m=grid[0].size();\n vector<vector<int>> dp(n, vector<int> (m,0) );\n int ans=0;\n\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){\n\n //very fir... |
3,338 | <p>You are given a <strong>0-indexed</strong> integer matrix <code>grid</code> and an integer <code>k</code>.</p>
<p>Return <em>the <strong>number</strong> of <span data-keyword="submatrix">submatrices</span> that contain the top-left element of the</em> <code>grid</code>, <em>and have a sum less than or equal to </em... | 2 | {
"code": "class Solution {\npublic:\n int countSubmatrices(vector<vector<int>>& grid, int k) {\n int n = grid.size(), m = grid[0].size();\n \n vector<vector<int>> sumGrid(n,vector<int>(m));\n int ans = 0;\n \n for(int i = 0; i < n; i++){\n for(int j = 0; j < m;... |
3,338 | <p>You are given a <strong>0-indexed</strong> integer matrix <code>grid</code> and an integer <code>k</code>.</p>
<p>Return <em>the <strong>number</strong> of <span data-keyword="submatrix">submatrices</span> that contain the top-left element of the</em> <code>grid</code>, <em>and have a sum less than or equal to </em... | 2 | {
"code": "class Solution {\npublic:\n int countSubmatrices(vector<vector<int>>& grid, int k) {\n int m=grid.size(),n=grid[0].size();\n vector<vector<int>> sums(m,vector<int>(n));\n int ans=0;\n for(int i=0;i<m;i++){\n int cur=0;\n for(int j=0;j<n;j++){\n ... |
3,338 | <p>You are given a <strong>0-indexed</strong> integer matrix <code>grid</code> and an integer <code>k</code>.</p>
<p>Return <em>the <strong>number</strong> of <span data-keyword="submatrix">submatrices</span> that contain the top-left element of the</em> <code>grid</code>, <em>and have a sum less than or equal to </em... | 3 | {
"code": "class Solution {\npublic:\n int countSubmatrices(vector<vector<int>>& grid, int k) {\n \n int n =grid.size();\n int m = grid[0].size();\n\n vector<vector<int>> dp(n+1,vector<int>(m+1,0));\n\n for(int i=1;i<=n;i++)\n {\n for(int j=1;j<=m;j++)\n ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 0 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n int m=grid.size();\n int y0=0,y1=0,y2=0;\n for(int i=0;i<m;i++)\n {\n for(int j=0;j<m;j++)\n {\n if(i==j && i<m/2 || (i+j==m-1 && i<m/2))\n ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 0 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n int m=grid.size();\n int y0=0,y1=0,y2=0;\n for(int i=0;i<m;i++)\n {\n for(int j=0;j<m;j++)\n {\n if(i==j && i<m/2 || (i+j==m-1 && i<m/2))\n ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 0 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n\n int rows = grid.size();\n int cols = grid[0].size();\n\n int zeroes_y = 0;\n int ones_y = 0;\n int twos_y = 0;\n int zeroes_non_y = 0;\n int ones_non_y = 0;\n ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 0 | {
"code": "class Solution {\nprivate:\n int minOps(vector<vector<int>> &grid, int y, int x){\n int res = 0;\n int n = grid.size();\n for(int i = 0; i<n; i++){\n for(int j = 0; j<n; j++){\n if(i <= n/2 && (i == j || i + j == n-1)){\n if(grid[i][j] !=... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 1 | {
"code": "class Solution {\npublic:\n\n bool Y(int i, int j, int n) {\n if ((i == j) && (i <= n/2)) {return true;}\n if ((i == n - 1 - j) && (i <= n/2)) {return true;}\n if ((i >= n/2) && (j == n/2)) {return true;}\n return false;\n }\n\n int minimumOperationsToWriteY(vector<vect... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 1 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n int n = grid.size();\n vector<int> inY(3, 0), notInY(3, 0);\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (i <= n/2) {\n if (i... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 1 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) \n {\n\n vector<int>y(3,0);\n vector<int>ny(3,0);\n\n\n\n for(int i=0;i<grid.size();i++)\n {\n for(int j=0;j<grid[0].size();j++)\n {\n ny[grid[i][j]]++... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 2 | {
"code": "class Solution {\n bool isY(int n,int x,int y){\n if(x<=n/2){\n if(x == y) return true;\n else if(x+y == n-1) return true;\n }\n else {\n if(y == n/2) return true;\n }\n return false;\n }\npublic:\n int minimumOperationsToWriteY(v... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 2 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n int N = grid.size();\n int center = N/2;\n vector<int> mp(3, 0);\n for(int i = 0; i < center; i++) {\n mp[grid[i][i]]++;\n }\n for(int i = 0; i < center; i++) {\n... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 2 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n int n=grid.size();\n vector<int>yc(3,0);\n vector<int>oc(3,0);\n\n for(int i=0;i<n/2;i++){\n yc[grid[i][i]]++;\n }\n int i=n/2-1;\n int j=n/2+1;\n wh... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 2 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n vector<int> y_cnt(3,0);\n vector<int> other_cnt(3,0);\n\n vector<int> all(3,0);\n\n int d_i = grid.size()/2;\n int d_j = grid[0].size()/2;\n\n for(int i=0;i<grid.size();i++)... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 2 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n int mid = grid.size() / 2;\n int n = grid.size() - 1;\n map<int, int> y, outsideOfY;\n for (int i = 0; i < grid.size(); i++) {\n int l = i;\n int r = n - i;\n ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 2 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n int mid = grid.size() / 2;\n int n = grid.size() - 1;\n map<int, int> y, outsideOfY;\n for (int i = 0; i < grid.size(); i++) {\n int l = i;\n int r = n - i;\n ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 2 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n int n = grid.size();\n map<int,int> y, noty;\n for (int i=0; i<n; i++) {\n for (int j=0; j<n; j++) {\n if(i < n/2 && (j == i || j == n-i-1)) y[grid[i][j]]++;\n ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 2 | {
"code": "class Solution {\npublic:\n static bool comp(pair<int,int>& p1,pair<int,int>& p2){\n return p1.second > p2.second;\n }\n int checkCase(vector<pair<int,int>>& belPair, vector<pair<int,int>>& nBelPair,int belVal,int nBelVal){\n int belCost = 0, nBelCost = 0;\n for(int i = 0;i < ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n //so cells which belong to letter Y is fixed\n //now the question is which digit among 0,1,2 should represent Y and non-y so that min number of operations are required\n map<int,int> cntonY,cnto... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n unordered_map<int, int> numCount;\n unordered_map<int, int> numCountForY;\n int midNum = grid.size() / 2;\n for(int row = 0; row < grid.size(); row++)\n {\n for(int col ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n map<int,int> mp1,mp2;\n\n int n = grid.size();\n int mid = n/2,county=0;\n\n for(int i=0;i<n;i++)\n {\n for(int j=0;j<n;j++)\n {\n if((i<mid an... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n int n = grid.size() ; \n int x = n/2 + 1 ; \n int t = n + (n/2) ; \n int tt = (n*n) - t ; \n unordered_map<int,int> mpp , npp ; \n for(int i = 0 ; i< n ; i++ ){\n ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n unordered_map<int,int> mp1,mp2;\n int n=grid.size();\n for(int i=0;i<n;i++){\n for(int j=0;j<n;j++){\n if((i==j && i<(n-1)/2) || (i+j==n-1 && i<(n-1)/2)\n ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n unordered_map<int,int> mp1;\n unordered_map<int,int> mp2;\n\n int n = grid.size();\n for(int i = 0;i < n;i++)\n {\n for(int j = 0;j < n;j++)\n {\n ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n unordered_map<int, int> in_map, out_map;\n int r = grid.size();\n int c = grid[0].size();\n in_map[0] = 0;\n in_map[1] = 0;\n in_map[2] = 0;\n out_map[0] = 0;\n ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "// Helper function to print pairs\ntemplate <typename T1, typename T2>\nstd::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &p)\n{\n return os << \"(\" << p.first << \", \" << p.second << \")\";\n}\n\n// Helper function to print containers like vector, set, etc.\ntemplate <typename Contai... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n int n = grid.size();\n unordered_set<int> s;\n vector<int> yCount(3,0), nonYcount(3,0);\n \n for(int i = 0, j = n-1; i <= n/2; i++, j--){\n //cout<<\"Inserting \"<<n*i +... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n unordered_map<int,int> uy;\n unordered_map<int,int> ny;\n int n=grid.size();\n int m=grid[0].size();\n uy[1]=uy[0]=uy[2]=ny[1]=ny[2]=ny[0]=0;\n for(int i=0;i<m;i++)\n ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n unordered_map<int,int> uy;\n unordered_map<int,int> ny;\n int n=grid.size();\n int m=grid[0].size();\n uy[1]=uy[0]=uy[2]=ny[1]=ny[2]=ny[0]=0;\n for(int i=0;i<m;i++)\n ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n int a = 0, b = 0, c = 0;\n for(auto i : grid)for(auto j : i){\n if(j == 0)a++;\n if(j == 1)b++;\n if(j == 2)c++;\n }\n int n = grid.size();\n int d... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n int n = grid.size();\n int mid = n / 2;\n\n map<int, int> mp; \n map<int, int> mp2; \n\n for (int i = 0; i <= mid; ++i) {\n mp[grid[i][i]]++;\n mp[grid[i][n ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& g) {\n vector<int> c(3), y(3);\n int n = g.size();\n for(auto i : g) for(auto j : i) c[j]++;\n for(int i = 0; i < n/2; i++) {\n y[g[i][i]]++;\n c[g[i][i]]--;\n y[g[... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int func(priority_queue<pair<int,int>> pq1,priority_queue<pair<int,int>> pq2,vector<int> y,vector<int> rest,bool flag){\n int sum =0;\n if(flag==true){\n pq1.pop();\n }\n else{\n pq2.pop();\n }\n \n for(in... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n int n = grid.size();int m = grid[0].size();\n int i=0;int j=0;int k=0;int l = n-1;\n \n unordered_map<int,int> y;unordered_map<int,int> not_y;map<pair<int,int>,int> mp;int y_cell = 0;int ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n int n=grid.size();\n vector<vector<int>> vis(n,vector<int> (n,0));\n int i=0,j=0;\n int cnt1=0,cnt0=0,cnt2=0;\n while(i<=(n/2)-1 and j<=(n/2)-1)\n {\n if(grid[i][... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n int n=grid.size();\n vector<vector<int>> vis(n,vector<int> (n,0));\n int i=0,j=0;\n int cnt1=0,cnt0=0,cnt2=0;\n while(i<=(n/2)-1 and j<=(n/2)-1)\n {\n if(grid[i][... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n void fill(vector<vector<int>>&vis,vector<vector<int>>& v) {\n int n=v.size();\n int i=0,j=0;\n while(i<=n/2) {\n vis[i][j]=1;\n i++;\n j++;\n }\n i=0,j=n-1;\n while(i<n/2) {\n vis[i][j]=1;\n... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "#include <iostream>\n#include <bits/stdc++.h>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n vector<int> os(3, 0);\n vector<int> ys(3, 0);\n auto n = grid.size();\n for(auto y = 0; y < grid.size(); y++) {\n ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n void fill(vector<vector<int>>&vis,vector<vector<int>>& v) {\n int n=v.size();\n int i=0,j=0;\n while(i<=n/2) {\n vis[i][j]=1;\n i++;\n j++;\n }\n i=0,j=n-1;\n while(i<n/2) {\n vis[i][j]=1;\n... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n void fill(vector<vector<int>>&vis,vector<vector<int>>& v) {\n int n=v.size();\n int i=0,j=0;\n while(i<=n/2) {\n vis[i][j]=1;\n i++;\n j++;\n }\n i=0,j=n-1;\n while(i<n/2) {\n vis[i][j]=1;\n... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n vector<int> change(3,0);\n vector<int> count(3,0);\n int n=grid.size();\n // for(int i=0;i<3;i++)cout<<change[i]<<\" \"<<count[i]<<\" \\n\";\n int left=n/2-1,right=n/2+1;\n ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n int n=grid.size();\n int left=0;\n int right=n-1;\n vector<vector<int>>lol(n,vector<int>(n,0));\n //maps for storing the y values\n map<int,int>mapsy;\n int y=0;\n ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n vector<vector<int>> v(n, vector<int>(m, -1));\n int i = 0;\n int cnt = 0, cnt1 = 0, cnt2 = 0;\n\n while (i < n / 2) {\n ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n vector<vector<int>> v(n, vector<int>(m, -1));\n int i = 0;\n int cnt = 0, cnt1 = 0, cnt2 = 0;\n\n while (i < n / 2) {\n ... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n return min(help(grid, 1), min(help(grid, 0), help(grid, 2)));\n }\n int help(vector<vector<int>>& grid, int y){\n int mid = grid.size()/2;\n set<pair<int, int>> st;\n pair<int, int>... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n return min(help(grid, 1), min(help(grid, 0), help(grid, 2)));\n }\n int help(vector<vector<int>>& grid, int y){\n int mid = grid.size()/2;\n set<pair<int, int>> st;\n pair<int, int>... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n return min(help(grid, 1), min(help(grid, 0), help(grid, 2)));\n }\n int help(vector<vector<int>>& grid, int y){\n int mid = grid.size()/2;\n set<pair<int, int>> st;\n pair<int, int>... |
3,335 | <p>You are given a <strong>0-indexed</strong> <code>n x n</code> grid where <code>n</code> is odd, and <code>grid[r][c]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</p>
<p>We say that a cell belongs to the Letter <strong>Y</strong> if it belongs to one of the following:</p>
<ul>
<li>The diagonal star... | 3 | {
"code": "class Solution {\npublic:\n int minimumOperationsToWriteY(vector<vector<int>>& grid) {\n return min(help(grid, 1), min(help(grid, 0), help(grid, 2)));\n }\n int help(vector<vector<int>>& grid, int y){\n int mid = grid.size()/2;\n set<pair<int, int>> st;\n pair<int, int>... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 0 | {
"code": "class Solution {\npublic:\n vector<int> resultArray(vector<int>& nums) {\n if (nums.size() == 1) {\n return nums;\n }\n vector<int> arr1, arr2;\n vector<int> cache1, cache2;\n\n auto it = nums.begin();\n arr1.reserve(nums.size());\n arr2.reserv... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 0 | {
"code": "class Solution {\npublic:\n int binsearch(vector<int>& arr, int target) \n {\n return arr.end()-upper_bound(arr.begin(),arr.end(),target);\n }\n vector<int> resultArray(vector<int>& nums) \n {\n int n=nums.size();\n // num,position\n vector<int>num1;\n vector<int>num2;... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 0 | {
"code": "class Fenwick {\n vector<int> tree;\npublic: \n Fenwick(int n) : tree(n + 1) {}\n\n void add(int i) {\n while (i < tree.size()) {\n tree[i]++;\n i += i & -i;\n }\n }\n\n int pre(int i) {\n int res = 0;\n while (i > 0) {\n res += tr... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 0 | {
"code": "class Fenwick{\n vector<int> tree;\npublic:\n Fenwick(int n) : tree(n){};\n void update(int i){\n for(; i < tree.size(); i += i & -i)\n tree[i]++;\n }\n\n int query(int i){\n int res = 0;\n for(; i > 0; i -= i & -i){\n res += tree[i];\n }\n ... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 0 | {
"code": "class Solution {\npublic:\n vector<int> resultArray(vector<int>& nums) {\n vector<int> arr1,sortedArr1,arr2,sortedArr2;\n arr1.push_back(nums[0]);\n sortedArr1.push_back(nums[0]);\n arr2.push_back(nums[1]);\n sortedArr2.push_back(nums[1]);\n int gc1,gc2;\n ... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 0 | {
"code": "class Solution {\npublic:\n vector<int> resultArray(vector<int>& nums) {\n \n vector<int> arr1Sorted, arr2Sorted, arr1, arr2;\n nums.insert(nums.begin(), 0);\n int n=nums.size();\n arr1Sorted.push_back(nums[1]);\n arr2Sorted.push_back(nums[2]);\n arr1.pus... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 0 | {
"code": "class Solution {\npublic:\n vector<int> resultArray(vector<int>& nums) {\n \n vector<int> arr1Sorted, arr2Sorted, arr1, arr2;\n nums.insert(nums.begin(), 0);\n int n=nums.size();\n arr1Sorted.push_back(nums[1]);\n arr2Sorted.push_back(nums[2]);\n arr1.pus... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 0 | {
"code": "template <class T>\nstruct FenwickTree {\n\n public:\n FenwickTree() : size(0), tree(0), msb(0) {}\n explicit FenwickTree(T n) : size(n), tree(n), msb(n ? static_cast<int>(log2(n)) : 0) {}\n\n int length() const {\n return size;\n }\n\n T operator[](T index)... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 0 | {
"code": "class Solution {\npublic:\n vector<int> resultArray(vector<int>& nums) {\n vector<int> m1, m2;\n vector<int> v1, v2;\n\n m1.push_back(nums[0]);\n m2.push_back(nums[1]);\n v1.push_back(nums[0]);\n v2.push_back(nums[1]);\n\n int x = 1, y = 1;\n\n for... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "template <typename T, typename K = int>\nstruct Fenwick {\n\tint n;\n\tvector<T> bit;\n\tFenwick() {} // For vector<Fenwick>.\n\tFenwick(int _n) : n(_n), bit(n + 1) {}\n\t/* 0 <= p < INT_MAX - 1. */\n\tvoid update(int p, T v) {\n\t\tfor (++p; p <= n; p += p & -p) bit[p] += v;\n\t}\n\t/* INT_MIN <= p < n. *... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "class Solution {\npublic:\n vector<int> resultArray(vector<int>& nums)\n {\n int n=nums.size();\n vector<int> a;\n vector<int> b;\n vector<int> A;\n vector<int> B;\n a.push_back(nums[0]);\n b.push_back(nums[1]);\n A.push_back(nums[0]);\n ... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "class Solution {\npublic:\n vector<int>vals;\n int len;\n void update(int val,int len,int id,vector<int>&bit)\n {\n while(id<=len)\n {\n bit[id]+=val;\n id+=(id & -id);\n }\n }\n int sum(int id,vector<int>&bit)\n {\n int sum=0;\n ... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "class Fenwick{\n vector<int>t;\n public:\n Fenwick(int n)\n {\n t.resize(n+1,0);\n }\n void update(int idx)\n {\n while(idx<t.size())\n {\n t[idx]+=1;\n idx+=(idx & -idx);\n }\n }\n int query(int idx)\n {\n int sum=0;\n ... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "struct Node {\n\n int key;\n int size; \n Node* left;\n Node* right;\n\n Node(int k, int s = 1, Node* l = nullptr, Node* r = nullptr)\n : key(k), size(s), left(l), right(r) {}\n};\n\nclass BalancedTree {\nprivate:\n Node* root;\n\n void updateSize(Node* node) {\n if (node... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "// AVL tree\nstruct Node {\n int key;\n int size;\n Node *left;\n Node *right;\n Node(int k, int s = 1, Node *l = NULL, Node *r = NULL) :\n key(k), size(s), left(l), right(r) {}\n};\n\nclass BalancedTree {\npublic:\n Node *root;\n\n void updateSize(Node *node) {\n if(node... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "class Solution {\npublic:\n\n void update(int i,int n, int *bit) {\n i+=1;\n while(i<=n) {\n bit[i]+=1;\n i+=(i&(-i));\n }\n }\n\n int range(int i, int *bit) {\n i+=1;\n int ans=0;\n while(i>0) {\n ans+=bit[i];\n ... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "class Solution {\npublic:\n vector<int>vals;\n void update(int val,int id,int node,int tl,int tr,vector<int>&tree)\n {\n if(tl==tr)\n {\n tree[node]+=val;\n return;\n }\n int mid=(tl+tr)/2;\n if(id<=mid)\n update(val,id,2*node,tl,... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "class BIT {\nprivate:\n vector<int> tree;\n int n;\n\npublic:\n BIT(int size) : tree(size + 1), n(size) {}\n\n void update(int idx, int val) {\n idx++;\n while (idx <= n) {\n tree[idx] += val;\n idx += idx & -idx;\n }\n }\n\n int query(int idx) {... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "#include<bits/stdc++.h>\n#include<ext/pb_ds/assoc_container.hpp>\n#include<ext/pb_ds/tree_policy.hpp>\nusing namespace __gnu_pbds;\nusing namespace std;\ntemplate <typename T>\nusing ordered_set = tree<T, null_type, greater_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;\n\nclass BIT{\nprivate:\... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "class Fenwick {\n vector<int> tree;\npublic:\n Fenwick(int n): tree(n) {}\n void add(int i) {\n while(i < tree.size()) {\n tree[i]++;\n i += i&(-i);\n }\n }\n int presum(int i) {\n int res = 0;\n while(i > 0) {\n res += tree[i];\n ... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "class Solution\n{\npublic:\n\n//GFG Fenwick tree start\n\n int getSum(int BITree[], int index)\n {\n int sum = 0; // Initialize result\n\n // index in BITree[] is 1 more than the index in arr[]\n index = index + 1;\n\n // Traverse ancestors of BITree[index]\n while ... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "class Solution {\npublic:\nclass node{\n public : \n int val ; \n node* left ; \n node* right ; \n int size ; \n node(int v ){\n left = NULL , right = NULL ; \n size = 1 ;\n val = v ; \n }\n}; \n class avl {\n public : \n node* root ; \... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "class Solution {\npublic:\n unordered_map<int,int> ind;\n vector<int> resultArray(vector<int>& nums) {\n vector<int> arr=nums;\n sort(arr.begin(),arr.end());\n if(nums.size()<3) return nums;\n int cnt=0,n=nums.size();\n for(int i=0;i<n;i++){\n int x=arr[i... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "class Solution {\npublic:\n struct FenwickTree{\n int n;\n vector<int> sums;\n FenwickTree(int n): n(n), sums(n) {}\n\n inline int most_right_bit(int value){\n return value & (-value);\n }\n void Update(int i, int amount){\n while(i < n){\n... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "#include <ranges>\n\nclass FenwickTree {\npublic:\n FenwickTree(int n)\n : tree(n, 0)\n {}\n\n void Add(int i, int value) {\n for (auto iOneBased = i+1; iOneBased <= tree.size(); iOneBased += Lsb(iOneBased)) {\n tree[iOneBased-1] += value;\n }\n }\n\n int Quer... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "struct fen\n{\n int n;\n vector<int> tr;\n\n fen(int n_)\n {\n n = n_;\n tr.assign(n, 0);\n }\n\n void inc(int pos, int v)\n {\n for (; pos < n; pos = (pos | (pos + 1)))\n tr[pos] += v;\n }\n\n int get(int pos)\n {\n int ret = 0;\n ... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "\ntypedef long long LL;\n#define MP make_pair\n#define PB push_back\n#define F first\n#define S second\n#define LB lower_bound\n#define UB upper_bound\n#define SZ(x) ((int)x.size())\n#define LEN(x) ((int)x.length())\n#define ALL(x) begin(x), end(x)\n#define RSZ resize\n#define ASS assign\n#define REV(x) re... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "class Solution {\n int n;\npublic:\n void update(vector<int> &bit,int val,int ind) {\n while(ind <= n) {\n bit[ind] += val;\n ind += (ind & -ind);\n }\n }\n int query(vector<int> &bit,int ind) {\n int ans = 0;\n while(ind > 0) {\n ans... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "class Solution {\npublic:\n int N; \n // update the Fenwick tree at index i with value val\n void updateFenwickTree(int i, int val, vector<int>& fenwickTree) {\n while (i < N) {\n fenwickTree[i] += val;\n i += (i & -i); // move to the next range that covers i\n ... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "typedef long long int ll;\n#define pii pair<int, int>\n#define F first\n#define S second\n\nstruct seg_tree {\n public:\n seg_tree(int _n) : n(_n){\n tree.resize(4*n, 0);\n }\n\n int query(int x, int y){\n return query(x, y, 0, n-1, 0);\n }\n\n vo... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "#include <vector>\n#include <algorithm>\n#include <unordered_map>\n#include <unordered_set>\nusing namespace std;\n\nclass SegmentTree {\npublic:\n SegmentTree(int n) : n(n) {\n tree.resize(4 * n, 0);\n }\n\n void update(int idx, int value, int node = 1, int l = 0, int r = -1) {\n if... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "class Solution {\npublic:\n vector<int> t1,t2;\n void update(vector<int>& t,int idx,int l,int r,int val)\n {\n if(l>val || r<val)\n return;\n if(l==r){\n t[idx]++;\n return;\n }\n int mid=(l+r)/2;\n update(t,2*idx,l,mid,val);\n ... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "#include <vector>\n#include <algorithm>\n#include <unordered_map>\n#include <unordered_set>\nusing namespace std;\n\nclass SegmentTree {\npublic:\n SegmentTree(int n) : n(n) {\n tree.resize(4 * n, 0);\n }\n\n void update(int idx, int value, int node = 1, int l = 0, int r = -1) {\n if... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "struct Node { \n int key; \n int height; \n int frequency;\n int lChildCount;\n int rChildCount;\n\n Node *left; \n Node *right; \n\n Node(int k) { \n this->key = k; \n this->left = nullptr; \n this->right = nullptr; \n this->height = 1;\n this->fr... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "struct Node* nullNode;\n\nstruct Node { \n int key; \n int height; \n int frequency;\n int lChildCount;\n int rChildCount;\n Node *left; \n Node *right; \n\n Node() {\n this->key = 0; \n this->left = nullptr; \n this->right = nullptr; \n this->height = 0;... |
3,350 | <p>You are given a <strong>1-indexed</strong> array of integers <code>nums</code> of length <code>n</code>.</p>
<p>We define a function <code>greaterCount</code> such that <code>greaterCount(arr, val)</code> returns the number of elements in <code>arr</code> that are <strong>strictly greater</strong> than <code>val</c... | 1 | {
"code": "struct Node* nullNode;\n\nstruct Node { \n int key; \n int height; \n int frequency;\n int lChildCount;\n int rChildCount;\n Node *left; \n Node *right; \n\n Node() {\n this->key = 0; \n this->left = nullptr; \n this->right = nullptr; \n this->height = 0;... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.