id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
40
<p>Given a collection of candidate numbers (<code>candidates</code>) and a target number (<code>target</code>), find all unique combinations in <code>candidates</code>&nbsp;where the candidate numbers sum to <code>target</code>.</p> <p>Each number in <code>candidates</code>&nbsp;may only be used <strong>once</strong> ...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> combinationSum2(vector<int>& candidates, int target) {\n vector<vector<int>> res;\n map<int, set<vector<int>>> imap, tempmap;\n \n sort(candidates.begin(), candidates.end());\n \n for (auto& val : candidates) {\n ...
40
<p>Given a collection of candidate numbers (<code>candidates</code>) and a target number (<code>target</code>), find all unique combinations in <code>candidates</code>&nbsp;where the candidate numbers sum to <code>target</code>.</p> <p>Each number in <code>candidates</code>&nbsp;may only be used <strong>once</strong> ...
3
{ "code": "class Solution {\npublic:\n void backtrack(vector<int> nums, int target, int ind, vector<vector<int>>& ans, vector<int> temp)\n {\n if(target == 0){\n ans.push_back(temp);\n return;\n }\n if(ind == nums.size() || target < nums[ind]) return;\n for(int ...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n const int rows = grid.size();\n const int cols = grid.front().size();\n const int modulo = rows * cols;\n k = k % modulo;\n if (k == 0)\n return std::move(grid);\...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n int rows = grid.size()-1;\n int columns = grid[0].size()-1;\n int previous = grid[0][0];\n for(int shift=0 ; shift<k ; shift++){\n for(int i=0 ; i<=rows ; i++){\n ...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n const int n = grid.size(), m = grid[0].size();\n\n vector<vector<int>> shifted(n, vector<int>(m));\n for(int i=0 ; i<n ; ++i) for(int j=0 ; j<m ; ++j)\n shifted[(i+(j+k)/m)%n][...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n int m = grid.size();\n int n = grid[0].size();\n std::vector<int> tmp(m, 0);\n for (;k > 0;--k){\n \n tmp[0] = grid[m - 1][n - 1];\n for (int i = 1...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n int m = grid.size();\n int n = grid[0].size();\n std::vector<int> tmp(m, 0);\n for (;k > 0;--k){\n \n tmp[0] = grid[m - 1][n - 1];\n for (int i = 1...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
1
{ "code": "/*\ntake the last one, swap it with the first one, and then the 2nd one, keep doing so until the last second one\nuse either nested loop or modulo to change line\ntime: O(m*n*k) \nspace: O(1)\n*/\nclass Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n int ...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
2
{ "code": "class Solution {\npublic:\n void R(int A[], int n){\n int L=A[n-1];\n for(int i=n-2;i>=0;i--)\n A[i+1]=A[i];\n A[0]=L;\n }\n void Rotate(int A[], int k,int n){\n if(k<0 || k>=n)\n return;\n for(int i=0;i<k;i++)\n R(A,n);\n }\n ...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n\n int sz = grid.size() * grid[0].size();\n vector<int> v(sz),ans(sz);\n\n int c1=0;\n for(int i=0; i<grid.size(); i++){\n for(int j=0; j<grid[i].size(); j++){\n ...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n int m=grid.size(),n=grid[0].size();\n vector<vector<int>>res(m, vector<int> (n,0));\n\n while(k)\n {\n for(int i=0;i<m;i++)\n {\n for(int j=1;j...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n int m = grid.size();\n int n = grid[0].size();\n int total = m * n;\n\n // Flatten the grid\n vector<int> flat(total);\n for (int i = 0; i < m; ++i) {\n for...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n int m = grid.size();\n int n = grid[0].size();\n int total = m * n;\n\n // Flatten the grid\n vector<int> flat(total);\n for (int i = 0; i < m; ++i) {\n for...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n int m=grid.size();\n int n=grid[0].size();\n while(k--){\n vector<int>temp(m);\n for(int i=0;i<m;i++){\n temp[i]=grid[i][n-1];\n }\n \n ...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n int sz = grid.size()*grid[0].size();\n k = k%sz;\n vector<int> result;\n for(int i=0;i<grid.size();i++){\n for(int j=0;j<grid[0].size();j++){\n result.pus...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n int rows = grid.size();\n int cols = grid[0].size();\n int totalElements = rows * cols;\n \n // Reduce k to a valid range (handle k > total elements)\n k = k % totalE...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n int m=grid.size();\n int n=grid[0].size();\n vector<vector<int>>result(m,vector<int>(n));\n vector<int>dummy;\n for(int i=0;i<m;i++)\n {\n for(int j=0;j<n;...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>> grid, int k) {\n std::vector<int> all;\n for (auto& v : grid) {\n all.insert(all.end(), v.begin(), v.end());\n }\n std::rotate(all.rbegin(), all.rbegin() + (k % all.size()), all.rend());\...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n int m = grid.size();\n int n = grid[0].size();\n k = k % (m * n);\n vector<int> flatGrid;\n for (const auto& row : grid) {\n flatGrid.insert(flatGrid.end(), row.b...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n vector<vector<int>> result(grid.size(), vector<int>(grid[0].size()));\n vector<int> ans;\n vector<int> temp;\n // if (grid[0].size() == 1 && grid.size() == 1) {\n // ret...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution {\npublic:\n\n void shifting(vector<int>&res,int k){\n vector<int>ans(res);\n for(int i=0;i<res.size();i++){\n int x = (i+k)%res.size();\n ans[x] = res[i]; \n }\n \n res = ans;\n \n }\n vector<vector<int>> shiftGrid(...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n int row, col;\n int m = grid.size(), n = grid[0].size();\n vector<int> flatGrid;\n vector<vector<int>> shiftedGrid(m, vector<int>(n));\n\n for (int i = 0; i < m; i++) {\n ...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n int row, col;\n int m = grid.size(), n = grid[0].size();\n vector<int> flatGrid;\n vector<vector<int>> shiftedGrid(m, vector<int>(n));\n\n for (int i = 0; i < m; i++) {\n ...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n vector<int> vec;\n for(auto it : grid) for(auto i : it) vec.push_back(i);\n for(int i=0;i<grid.size();i++){\n for(int j=0;j<grid[i].size();j++){\n int pos = vec....
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n\n vector<vector<int>> res;\n\n for(int i = 0; i < grid.size(); i++){\n vector<int> t;\n for(int j = 0; j < grid[0].size(); j++){\n t.push_back(grid[i][j]);\n...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n int n=grid.size();\n int m=grid[0].size();\n k=k%(m*n);\n \n if(k==0)\n return grid;\n\n vector<int> v;\n for(int i=0;i<n;i++){\n for(int j=0...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n int n = grid[0].size();\n vector<int> vc;\n for(int i = 0; i < grid.size(); ++i) {\n for(int j = 0; j < grid[i].size(); ++j) {\n vc.push_back(grid[i][j]);\n ...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n vector<int> t;\n int start = 0;\n int n = grid[0].size();\n\n for (auto i: grid) \n t.insert(t.end(), i.begin(), i.end());\n\n vector<int> s(t.end() - k % t.size(...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n vector<int> t;\n int start = 0;\n int n = grid[0].size();\n\n for (auto i: grid) \n t.insert(t.end(), i.begin(), i.end());\n\n vector<int> s(t.end() - k % t.size(...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution \n{\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) \n {\n int m = grid.size(), n = grid[0].size(), i;\n\n k %= (m * n);\n\n for(i = 0; i < k; i++)\n {\n helper(grid);\n }\n\n return grid;\n }\n\nprivate...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n vector<vector<int>> result(grid.size(), vector<int>(grid[0].size()));\n vector<int> ans;\n vector<int> temp;\n if (grid[0].size() == 1 && grid.size() == 1) {\n return gr...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution \n{\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) \n {\n int m = grid.size(), n = grid[0].size(), i;\n\n k %= (m * n);\n\n for(i = 0; i < k; i++)\n {\n helper(grid);\n }\n\n return grid;\n }\n\nprivate...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution \n{\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) \n {\n int m = grid.size(), n = grid[0].size(), i;\n\n k %= (m * n);\n\n for(i = 0; i < k; i++)\n {\n helper(grid);\n }\n\n return grid;\n }\n\nprivate...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n vector<int> temp;\n for(int i=0;i<grid.size();++i)\n {\n for(int j=0;j<grid[i].size();++j) \n temp.push_back(grid[i][j]);\n }\n for(int i=0;i<...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n for (int i=1;i<=k;i++){\n int size = grid.size();\n vector<int> tmp;\n for (int p=0;p<grid.size();p++){\n for (int q=grid[0].size()-1;q>=0;q--){\n ...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n int m = grid.size(), n = grid[0].size();\n\n while (k--) {\n vector<int> cols;\n cols.push_back(grid[m - 1].back());\n grid[m - 1].pop_back();\n\n for...
1,386
<p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p> <p>In one shift operation:</p> <ul> <li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li> <li>Element at <code>grid[i][n -...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {\n int row=grid.size();\n vector<vector<int>> m;\n int col=grid[0].size();\n int i,j;\n vector<int> v;\n vector<int> nv;\n k=k%(row*col);\n for(i=0;i<row;i...
1,395
<p>On a 2D plane, there are <code>n</code> points with integer coordinates <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. Return <em>the <strong>minimum time</strong> in seconds to visit all the points in the order given by </em><code>points</code>.</p> <p>You can move according to these rules:</p> <ul> <l...
0
{ "code": "class Solution {\npublic:\n int minTimeToVisitAllPoints(vector<vector<int>>& points) {\n int len = points.size();\n int time = 0;\n for (int i=0; i < len - 1; i++) {\n int diff_x = points[i + 1][0] - points[i][0];\n diff_x *= (diff_x < 0) ? -1 : 1;\n ...
1,395
<p>On a 2D plane, there are <code>n</code> points with integer coordinates <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. Return <em>the <strong>minimum time</strong> in seconds to visit all the points in the order given by </em><code>points</code>.</p> <p>You can move according to these rules:</p> <ul> <l...
0
{ "code": "class Solution {\npublic:\n int minTimeToVisitAllPoints(vector<vector<int>>& points)\n { int n = points.size();\n int result = 0;\n\n for(int i=1;i<n;i++)\n result += max(abs(points[i][0]-points[i-1][0]), \n abs(points[i][1]-points[i-1][1]));\n ...
1,395
<p>On a 2D plane, there are <code>n</code> points with integer coordinates <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. Return <em>the <strong>minimum time</strong> in seconds to visit all the points in the order given by </em><code>points</code>.</p> <p>You can move according to these rules:</p> <ul> <l...
0
{ "code": "class Solution {\npublic:\n int minTimeToVisitAllPoints(vector<vector<int>>& points) {\n int n = points.size(), res = 0;\n for(int i = 1; i < n; i++) res += max(abs(points[i][0] - points[i - 1][0]), abs(points[i][1]- points[i - 1][1]));\n return res;\n }\n};", "memory": "13200"...
1,395
<p>On a 2D plane, there are <code>n</code> points with integer coordinates <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. Return <em>the <strong>minimum time</strong> in seconds to visit all the points in the order given by </em><code>points</code>.</p> <p>You can move according to these rules:</p> <ul> <l...
0
{ "code": "class Solution {\npublic:\n int minTimeToVisitAllPoints(vector<vector<int>>& p) {\n int ans=0,mini,maxi;\n for(int i=1;i<p.size();i++){\n mini=min(abs(p[i][0]-p[i-1][0]),abs(p[i][1]-p[i-1][1]));\n maxi=max(abs(p[i][0]-p[i-1][0]),abs(p[i][1]-p[i-1][1]));\n a...
1,395
<p>On a 2D plane, there are <code>n</code> points with integer coordinates <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. Return <em>the <strong>minimum time</strong> in seconds to visit all the points in the order given by </em><code>points</code>.</p> <p>You can move according to these rules:</p> <ul> <l...
0
{ "code": "class Solution {\npublic:\n int sum = 0;\n int minTimeToVisitAllPoints(vector<vector<int>>& points) {\n for(int i = 1 ; i < points.size(); i++){\n if(abs(points[i][0] - points[i-1][0]) >= abs(points[i][1] - points[i-1][1])){\n sum += abs(points[i][0] - points[i-1][0])...
1,395
<p>On a 2D plane, there are <code>n</code> points with integer coordinates <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. Return <em>the <strong>minimum time</strong> in seconds to visit all the points in the order given by </em><code>points</code>.</p> <p>You can move according to these rules:</p> <ul> <l...
1
{ "code": "class Solution {\npublic:\n int minTimeToVisitAllPoints(vector<vector<int>>& points) {\n int totalTime = 0;\n\n for(int i = 1; i < points.size(); i++)\n {\n int x1 = points[i - 1][0];\n int y1 = points[i - 1][1];\n int x2 = points[i][0];\n ...
1,395
<p>On a 2D plane, there are <code>n</code> points with integer coordinates <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. Return <em>the <strong>minimum time</strong> in seconds to visit all the points in the order given by </em><code>points</code>.</p> <p>You can move according to these rules:</p> <ul> <l...
1
{ "code": "class Solution {\npublic:\n int minTimeToVisitAllPoints(vector<vector<int>>& points) {\n \n int time=0;\n for(int i=1;i<points.size();i++){\n int diffx = abs(points[i][0]-points[i-1][0]);\n int diffy = abs(points[i][1]-points[i-1][1]);\n int mindiff=min(diffx, diffy);\n...
1,395
<p>On a 2D plane, there are <code>n</code> points with integer coordinates <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. Return <em>the <strong>minimum time</strong> in seconds to visit all the points in the order given by </em><code>points</code>.</p> <p>You can move according to these rules:</p> <ul> <l...
3
{ "code": "class Solution {\npublic:\n int minTimeToVisitAllPoints(vector<vector<int>>& points) {\n int totalTime = 0;\n for(int i = 1; i < points.size(); i++) {\n int dx = abs(points[i][0] - points[i-1][0]);\n int dy = abs(points[i][1] - points[i-1][1]);\n totalTime ...
1,395
<p>On a 2D plane, there are <code>n</code> points with integer coordinates <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. Return <em>the <strong>minimum time</strong> in seconds to visit all the points in the order given by </em><code>points</code>.</p> <p>You can move according to these rules:</p> <ul> <l...
3
{ "code": "class Solution {\npublic:\n int minTimeToVisitAllPoints(vector<vector<int>>& points) {\n vector<int> current = points[0];\n int seconds = 0;\n for(int i = 1; i < points.size(); i++){\n vector<int> target = points[i];\n int xOff = 0; int yOff = 0;\n w...
1,395
<p>On a 2D plane, there are <code>n</code> points with integer coordinates <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. Return <em>the <strong>minimum time</strong> in seconds to visit all the points in the order given by </em><code>points</code>.</p> <p>You can move according to these rules:</p> <ul> <l...
3
{ "code": "class Solution {\npublic:\n int minTimeToVisitAllPoints(vector<vector<int>>& points) {\n int i = points[0][0] ,j = points[0][1] ,s = 0;\n for(vector<int> x : points)\n {\n i -= x[0];\n j -= x[1];\n if(i < 0) i = -i;\n if(j < 0) j = -j;\n ...
1,514
<p>Given an array of integers&nbsp;<code>nums</code>, you start with an initial <strong>positive</strong> value <em>startValue</em><em>.</em></p> <p>In each iteration, you calculate the step by step sum of <em>startValue</em>&nbsp;plus&nbsp;elements in <code>nums</code>&nbsp;(from left to right).</p> <p>Return the mi...
0
{ "code": "class Solution {\npublic:\n int minStartValue(vector<int>& nums) {\n int mini = nums[0];\n\n for(int i=1; i<nums.size(); i++){\n nums[i] = nums[i] + nums[i-1];\n mini = min(mini, nums[i]);\n }\n\n if(mini <=0)\n return 1 + (-1 * mini);\n ...
1,514
<p>Given an array of integers&nbsp;<code>nums</code>, you start with an initial <strong>positive</strong> value <em>startValue</em><em>.</em></p> <p>In each iteration, you calculate the step by step sum of <em>startValue</em>&nbsp;plus&nbsp;elements in <code>nums</code>&nbsp;(from left to right).</p> <p>Return the mi...
0
{ "code": "class Solution {\npublic:\n int minStartValue(vector<int>& nums) \n {\n int curr_min_val = nums[0];\n int startValue = 1;\n\n while(startValue + curr_min_val < 1)\n {\n startValue++;\n }\n \n for (int i = 1; i < nums.size(); ++i)\n {\...
1,514
<p>Given an array of integers&nbsp;<code>nums</code>, you start with an initial <strong>positive</strong> value <em>startValue</em><em>.</em></p> <p>In each iteration, you calculate the step by step sum of <em>startValue</em>&nbsp;plus&nbsp;elements in <code>nums</code>&nbsp;(from left to right).</p> <p>Return the mi...
0
{ "code": "class Solution {\npublic:\n int minStartValue(vector<int>& nums) {\n int j = -1;\n\n for (int i = 0; i < nums.size(); ++i) {\n if (nums[i] < 0) {\n j = i;\n }\n }\n\n if (j < 0) {\n return 1;\n }\n\n int result = a...
1,514
<p>Given an array of integers&nbsp;<code>nums</code>, you start with an initial <strong>positive</strong> value <em>startValue</em><em>.</em></p> <p>In each iteration, you calculate the step by step sum of <em>startValue</em>&nbsp;plus&nbsp;elements in <code>nums</code>&nbsp;(from left to right).</p> <p>Return the mi...
0
{ "code": "class Solution {\npublic:\n int minStartValue(vector<int>& nums) {\n int mn = 0,sum=0;\n for(int i=0;i<nums.size();i++){\n sum+=nums[i];\n mn=min(mn,sum);\n }\n return abs(mn)+1;\n }\n};", "memory": "9100" }
1,514
<p>Given an array of integers&nbsp;<code>nums</code>, you start with an initial <strong>positive</strong> value <em>startValue</em><em>.</em></p> <p>In each iteration, you calculate the step by step sum of <em>startValue</em>&nbsp;plus&nbsp;elements in <code>nums</code>&nbsp;(from left to right).</p> <p>Return the mi...
1
{ "code": "class Solution {\npublic:\n int minStartValue(vector<int>& nums) {\n int psum=0,ans=0;\n for(auto i:nums)\n {\n psum+=i;\n if(psum < 0)\n ans=max(ans,abs(psum));\n }\n return ans+1;\n }\n};", "memory": "9200" }
1,514
<p>Given an array of integers&nbsp;<code>nums</code>, you start with an initial <strong>positive</strong> value <em>startValue</em><em>.</em></p> <p>In each iteration, you calculate the step by step sum of <em>startValue</em>&nbsp;plus&nbsp;elements in <code>nums</code>&nbsp;(from left to right).</p> <p>Return the mi...
1
{ "code": "class Solution {\npublic:\n int minStartValue(vector<int>& nums) {\n int m = nums[0];\n for(int i = 1, n = nums.size();i < n; i++){\n nums[i]+=nums[i-1];\n m = min(m, nums[i]);\n }\n return m >= 1 ? 1 : m * -1 + 1;\n }\n};", "memory": "9200" }
1,514
<p>Given an array of integers&nbsp;<code>nums</code>, you start with an initial <strong>positive</strong> value <em>startValue</em><em>.</em></p> <p>In each iteration, you calculate the step by step sum of <em>startValue</em>&nbsp;plus&nbsp;elements in <code>nums</code>&nbsp;(from left to right).</p> <p>Return the mi...
2
{ "code": "class Solution {\npublic:\n int minStartValue(vector<int>& nums) {\n int n=nums.size();\n int mn=nums[0];\n for(int i=1;i<n;i++)\n {\n nums[i]+=nums[i-1];\n if(nums[i]<mn)\n {\n mn=nums[i];\n }\n }\n if(mn>0)\n return 1;\n el...
1,514
<p>Given an array of integers&nbsp;<code>nums</code>, you start with an initial <strong>positive</strong> value <em>startValue</em><em>.</em></p> <p>In each iteration, you calculate the step by step sum of <em>startValue</em>&nbsp;plus&nbsp;elements in <code>nums</code>&nbsp;(from left to right).</p> <p>Return the mi...
2
{ "code": "class Solution {\npublic:\n int minStartValue(vector<int>& nums) {\n vector<int> partsum(nums.size(), 0);\n partial_sum(nums.begin(), nums.end(), partsum.begin());\n std::vector<int>::iterator result = min_element(partsum.begin(), partsum.end());\n return max(1-(*result), 1);...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n int numberOfArrays(string s, int k) {\n int MOD = 1000000007;\n int n = 0;\n for (int i = k; i > 0; i /= 10) {\n n++;\n }\n vector<int> dp(n, 1);\n for (int i = 0; i < s.size(); i++) {\n int next = 0;\n ...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n int numberOfArrays(string s, int k) {\n static const int MOD = 1e9 + 7;\n int klen = to_string(k).length();\n vector<int> dp(klen + 1);\n dp[s.length() % dp.size()] = 1;\n for (int i = s.length() - 1; i >= 0; --i) {\n dp[i % dp.si...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n const static int mod = 1e9 + 7 ;\n int numberOfArrays(string s, int k) {\n int n = s.size() ; \n int dp[n+1] ; \n dp[n] = 1 ;\n for(int i = n-1; i >= 0 ; i-- ){\n int ways = 0 ; \n if(s[i] != '0'){\n long lon...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n typedef long long ll;\n ll mod = 1e9+7;\n int numberOfArrays(string s, int k) {\n int n = s.length();\n ll dp[n+1];\n dp[n] = 1;\n ll temp=0;\n for(int i=n-1; i>=0; i--){\n temp = 0;\n dp[i] = 0;\n for(...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n #define ll long long int\n const int mod = 1e9+7;\n ll dp[100001];\n int k;\n\n ll dfs(ll ind, string &s){\n int n = s.size();\n if(ind==n)return 1;\n if(s[ind]=='0') return 0;\n\n if(dp[ind]!=-1)return dp[ind];\n\n ll ans = 0;\n...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n int numberOfArrays(string s, int k) {\n const int mod = 1e9+7;\n long long n = s.size();\n s+='5';\n long long dp[n+1];\n dp[n] = 1;\n for(long long i=n-1;i>=0;i--){\n dp[i] = 0;\n if(s[i] == '0') continue;\n ...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n int numberOfArrays(string &s, int k) {\n int n = s.size();\n int mod = 1e9+7;\n vector<int>dp(n+1,0);\n dp[n] = 1;\n for(int i =n-1;i>=0;i--){\n long long num = 0, ans = 0;\n if(s[i] != '0')\n for(int j = i;j<n;j++...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n int numberOfArrays(string s, int k) {\n int n = s.size();\n int mod = 1000000007;\n int* dp = new int[n];\n for(int i = n-1; i >= 0; i--){\n if(s[i] != '0'){\n int ans = 0;\n long x = 0;\n int...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\n typedef long long LL;\npublic:\n int numberOfArrays(string s, int k) {\n const int MOD = 1e9 + 7;\n int N = s.size();\n \n // Edge case: if the first character is greater than k, return 0\n if (s[0] - '0' > k) return 0;\n\n // Calculate the...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\n int mod=1e9+7;\n int f(int strt,string s,int k)\n {\n if(strt>=s.length())\n return 1;\n if(s[strt]=='0')\n return 0;\n\n long long ans=0,num=0;\n for(int end=strt;end<s.length();end++)\n {\n num=num*10+s[end]-'0';\n ...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\n const int mod = 1e9 + 7;\npublic:\n int numberOfArrays(string s, int k) {\n int n = s.size();\n\n vector<int> dp(n+1);\n if (s[0] == '0') return 0;\n\n dp[0] = 1;\n for (int i = 1 ; i <= n ; i++) {\n for (int j = 0, k1 = i ; j < 10 && k...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n long long int dp[100001];\n bool isValid(string s,long long int k){\n if(s[0]=='0') return false;\n if(s==\"0\" || stoll(s)>k) return false;\n return true;\n }\n \n\t int numberOfArrays(string s, int k) {\n string ...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n long long int dp[100001];\n bool isValid(string s,long long int k){\n if(s[0]=='0') return false;\n if(s==\"0\" || stoll(s)>k) return false;\n return true;\n }\n \n\t int numberOfArrays(string s, int k) {\n string ...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n int mod = 1e9+7;\n int solve(int index, string& s, int& k,vector<int>& dp){\n if(index>=s.size())\n return 1;\n if(s[index]=='0')\n return 0;\n if(dp[index]!=-1)\n return dp[index];\n int ans=0;\n long num...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n using ll = long long;\n long long mod = 1e9 + 7;\n \n int solve(string s,int k){\n \n vector<int>dp(s.size() + 1,0);\n dp[0] = 1;\n\n for(int idx = 0 ; idx < s.size() ; idx ++ ){ \n ll num = 0;\n int count = 0;\n ...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n const int mod = 1e9 + 7;\n int numberOfArrays(string s, int k) {\n vector<int> dp(s.size()+1,-1);\n // return func(0,s,k,dp);\n dp[s.size()] = 1;\n int prev = 0,next = 1;\n for(int ind = s.size()-1;ind >= 0;ind--){\n string tem...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "#define ll long long\nclass Solution {\npublic:\n const int mod=(int)1e9+7;\n int numberOfArrays(string s, int k) {\n int n=s.size();\n vector<int>dp(n+1);\n if((s[0]-'0')>=1 && (s[0]-'0')<=k){\n dp[0]=1;\n }\n int num=k,dig=0;\n while(num>0){\n ...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n int mod = 1e9 + 7;\n int numberOfArrays(string s, int k) {\n vector<int> dp(s.size()+1,-1);\n // return func(0,s,k,dp);\n dp[s.size()] = 1;\n int prev = 0,next = 1;\n for(int ind = s.size()-1;ind >= 0;ind--){\n string temp;\n ...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\n const int mod=1e9+7;\n int f(int i, int j, string& s, int k, vector<int>& dp){\n if(dp[i]!=-1)\n return dp[i];\n if(i>j)\n return dp[i]=0;\n if(s[i]=='0')\n return 0;\n long long res=0;\n for(int idx=i;idx<=j;idx++...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n int MOD = 1e9+7;\n int fn(int ind, string s, int k, vector<int> &dp, int n){\n \n if(s[ind] == '0') return dp[ind] = 0;\n if(ind>=n) return 1;\n string temp = \"\";\n int sum = 0;\n if(dp[ind] != -1) return dp[ind]%MOD;\n co...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "typedef long long ll;\nusing vi = vector<int>;\nclass Solution {\npublic:\n int n;\n int k;\n\n int mod = 1e9 + 7;\n\n bool valid(string &str, ll k){\n // cout<<str<<\" \"<<(stoi(str) <= k)<<\"\\n\";\n return (stol(str) <= k);\n }\n\n\n int numberOfArrays(string s, int _k) {...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\n int MOD = 1e9 + 7;\npublic:\n int numberOfArrays(string s, int k) {\n int n = s.length();\n int klen = to_string(k).length();\n\n vector<int> dp(n, 0);\n\n if(k < (s[0] - '0'))\n return 0;\n dp[0] = 1;\n\n for(int i = 1; i < n; i...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\nint mod=1000000007;\n int numberOfArrays(string s, int k) {\n int n=s.size();\n vector<long long> dp(n+1,0);\n dp[n]=1;\n //1317\n for(int i=n-1;i>=0;i--){\n if(s[i]=='0') dp[i]=0;\n else{\n long long x=s...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n int numberOfArrays(string s, int k) {\n int n=(int)s.length();\n string ss=to_string(k);\n const long long mod=(long long)(1e9)+7;\n vector<long long>dp(n+1,0);\n dp[n]=1;\n for(int i=n-1;i>=0;i--)\n {\n long long y=...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\nusing namespace __gnu_pbds;\n/*\n * CUSTOM hash function which avoids collisions and hence makes unordered maps / sets faster\n */\nstruct custom_hash\n{\n static uint64_t spli...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n int numberOfArrays(string s, int k) {\n long long curv = 0;\n int n_pos = 0;\n int n = s.size();\n vector<long long> dp(n+1);\n //queue<int> maxv;\n //vector<int> k_str;\n int k_ = k;\n long long nk = 0;\n while (...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n int numberOfArrays(string s, int k) {\n long long curv = 0;\n int n_pos = 0;\n int n = s.size();\n vector<long long> dp(n+1);\n //queue<int> maxv;\n //vector<int> k_str;\n int k_ = k;\n long long nk = 0;\n while (...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n int numberOfArrays(string s, int k) {\n long long curv = 0;\n int n_pos = 0;\n int n = s.size();\n vector<long long> dp(n+1);\n //queue<int> maxv;\n //vector<int> k_str;\n int k_ = k;\n long long nk = 0;\n while (...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n const int MOD = 1e9+7;\nbool check(string s1,int k){\n string t = to_string(k);\n if(t.length()<s1.length()) return false;\n if(t.length()==s1.length() && t.length()==10){\n if(s1[0]=='0') return false;\n for(int i=0;i<10;i++){\n ...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n int numberOfArrays(string s, int k) {\n int n = s.size();\n int mod = 1000000007;\n vector<int> dp(n,0);\n\n dp[0]= (s[0]-'0')<=k?1:0;\n\n for(int i=1;i<s.size();i++){\n int t = s[i]-'0';\n if(t>=1 && t<=k)\n ...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n int numberOfArrays(string s, int k) {\n const int mod=(int)1e9+7;\n int n=s.size();\n int ind=0;\n int cnt=0;\n for(int i=0;i<n;i++){\n if(s[i]!='0' && cnt==0) ind=i;\n else if(s[i]!='0' && i!=n-1){\n str...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "class Solution {\npublic:\n int numberOfArrays(string s, int k) {\n int n = s.length();\n int mod = 1e9+7;\n vector<long long>dp(n+1,0);\n dp[n] = 1;\n for(int i=n-1;i>=0;i--){\n if(s[i] == '0') continue;\n for(int j=1;j<=min(10,n-i);j++){\n ...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
0
{ "code": "typedef long long int ll;\nconst ll mod=1e9+7;\n\nclass Solution {\npublic:\n int numberOfArrays(string s, int k) {\n int n=s.size();\n vector<ll> dp(n+2);\n dp[0]=1;\n\n for(int i=1;i<=n;i++){\n for(int j=1;j<=10;j++){\n if(i-j<0) continue;\n ...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
1
{ "code": "class Solution {\npublic:\n int mod = 1e9 + 7;\n int numberOfArrays(string s, int k) {\n int n = s.size();\n vector<long long> dp(n+1, 1);\n int len = to_string(k).length();\n for(int start = n-1; start>=0; start--) {\n int count = 0;\n for(int i=star...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
1
{ "code": "class Solution {\npublic:\n int mod = 1e9 + 7;\n int numberOfArrays(string s, int k) {\n int n = s.size();\n vector<long long> dp(n+1, 1);\n int len = to_string(k).length();\n for(int start = n-1; start>=0; start--) {\n int count = 0;\n for(int i=star...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
1
{ "code": "class Solution {\npublic:\n typedef long long ll;\n ll mod = 1e9+7;\n ll t[100001]; \n\n ll solve(ll start,string &s,ll k,ll n){\n if(start>=n) return 1;\n if(s[start]=='0') return 0;\n if(t[start]!=-1) return t[start];\n\n ll ans = 0;\n ll num = 0;\n f...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
1
{ "code": "class Solution {\npublic:\n #define ll long long int\n const int mod = 1e9+7;\n ll dp[100001];\n int k;\n\n ll dfs(ll ind, string &s){\n int n = s.size();\n if(ind == n) return 1; // Reached end, valid partition\n if(s[ind] == '0') return 0; // Leading zero, invalid part...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
1
{ "code": "class Solution {\npublic:\n #define ll long long int\n const int mod = 1e9+7;\n ll dp[100001];\n int k;\n\n ll dfs(ll ind, string &s){\n int n = s.size();\n if(ind==n)return 1;\n if(s[ind]=='0') return 0;\n\n if(dp[ind]!=-1)return dp[ind];\n\n ll ans = 0;\n...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
1
{ "code": "typedef long long ll;\nconstexpr int P = 1e9+7, N = 1e6;\nclass Solution {\nprivate:\n ll f[N];\n int check(int l,int r, string&s,int k)\n {\n if(s[l]=='0')\n return 0;\n ll m = 0;\n for(int i=l;i<=r;i++)\n {\n m=m*10+s[i]-'0';\n if(m>k)...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
1
{ "code": "typedef long long ll;\nconstexpr int P = 1e9+7, N = 1e6;\nclass Solution {\nprivate:\n ll f[N];\n int check(int l,int r, string&s,int k)\n {\n if(s[l]=='0')\n return 0;\n ll m = 0;\n for(int i=l;i<=r;i++)\n {\n m=m*10+s[i]-'0';\n if(m>k)...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
1
{ "code": "typedef long long ll;\nconstexpr int P = 1e9+7, N = 1e6;\nclass Solution {\nprivate:\n ll f[N];\n int check(int l,int r, string&s,int k)\n {\n if(s[l]=='0')\n return 0;\n ll m = 0;\n for(int i=l;i<=r;i++)\n {\n m=m*10+s[i]-'0';\n if(m>k)...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
1
{ "code": "class Solution {\npublic:\n int mod = 1e9+7;\n int dp[100001];\n int solve(string &s,int idx,int k){\n if(idx==s.length()) return 1;\n if(s[idx]=='0') return 0;\n if(dp[idx]!=-1) return dp[idx];\n long long num = 0;\n long long ans = 0;\n for(int i=idx;i<s...
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
1
{ "code": "class Solution {\npublic:\n const int mod = 1e9 + 7;\n long dp[100001];\n long solve(int idx, string &s, int k)\n {\n if (idx == s.size())\n return 1;\n\n if (dp[idx] != -1)\n return dp[idx];\n\n long sum = 0, ans = 0;\n for (int i = idx; i < s....
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
1
{ "code": "long dp[100005];\nconst int MOD = 1e9 + 7;\nclass Solution {\npublic:\n long helper(string &s, int &k, int ind){\n if(ind == s.length())return 1;\n if(s[ind] == '0')return 0;\n if(dp[ind] != -1)return dp[ind];\n long long int num = 0, ans = 0;\n for(int i = ind; i < s....
1,517
<p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <co...
1
{ "code": "class Solution {\npublic:\n int c = 0;\n int mod = 1e9 + 7;\n long long dp[100100];\n long long rec(int level,string& s,int& k){\n //pruning and base case\n if(level == s.size()){\n return 1;\n }\n\n if(s[level] == '0'){\n return 0;\n }\n...