id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n ...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "class Solution {\npublic:\n Node* construct(vector<vector<int>>& grid) {\n int n = grid.size();\n return constructTree(grid, {{0, 0}, {n - 1, n - 1}});\n }\n\n Node* constructTree(vector<vector<int>>& grid, vector<vector<int>> boundary) {\n int x1 = boundary[0][0], y1 = bounda...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n ...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n ...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n ...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n ...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n\n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n b...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n ...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n ...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n ...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n ...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n ...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n ...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n ...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n ...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n ...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n ...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n ...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n ...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n ...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n ...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n ...
772
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p> <p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p> <p>A Quad-Tree is a tree data structure in which each internal nod...
3
{ "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
0
{ "code": "static const int speedup = []{ios::sync_with_stdio(0); cin.tie(0); return 0;}();\n\nclass Solution {\npublic:\n std::vector<int> getAverages(std::vector<int>& nums, int k) {\n long long sum = 0;\n int bound = 2 * k + 1;\n std::vector<int> ans;\n ans.resize(nums.size(), -1...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
0
{ "code": "#pragma GCC optimize(\"O3\")\nclass Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n int n = nums.size();\n int len = 2*k + 1;\n vector<int> result(n, -1);\n if (n < len) r...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
0
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n std::vector<int> output(nums.size(),-1);\n long int initial_sum = 0;\n for(size_t i =0; i<(2*k) && i<nums.size();i++){\n initial_sum += nums[i];\n //std::cout << \"Adding \" << nu...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
0
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n std::vector<int> output(nums.size(),-1);\n long int initial_sum = 0;\n for(size_t i =0; i<(2*k) && i<nums.size();i++){\n initial_sum += nums[i];\n //std::cout << \"Adding \" << nu...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
1
{ "code": "#include <algorithm>\n\nclass Solution {\npublic:\n\n/*\nn = 4;\n l x r \n l c r\n[1,1,1,1]\nk = 1\nwindowSize = 3;\n\ncurrTotal = nums[0....6]\ncentre = 1\n\navgs [-1, 1,-1,-1]\n \nright = 2\ncurrTotal = 3 \n\n l c r\n[1,1,1,1]\n\n*/\n\n vector<int> getAverages(vector<int>& nums, int k) {\n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
1
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> avgs(n, -1);\n if (k == 0) return nums;\n if (2 * k + 1 > n) return avgs;\n long long sum = 0;\n for (int i = 0; i < 2 * k + 1; ++i) {\n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n=nums.size();\n long long int pref[n+1];\n vector<int> ans(n);\n pref[0]=0;\n for(int i=0;i<n;i++){\n pref[i+1]=pref[i]+nums[i];\n }\n for(int i=0;i<n;i++){\...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<int> avgs(nums.size());\n long long running = 0;\n if (k == 0) {\n return nums;\n }\n bool tf = (nums.size() < 2*k + 1);\n std::cout << tf << endl;;\n if (...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int len = nums.size();\n int step = 2*k+1;\n vector<int> avg(len, -1);\n if(k == 0) return nums;\n if(len < step) \n {\n vector<int> res(len, -1);\n return re...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<int> ans(nums.size(), -1); \n if(ans.size() < 2*k+1) return ans; \n stack<int> st; long long int t = 0; \n int s = 1, e = 2*k+1; \n for(int i=0; i<=2*k; i++) t += nums[i]; st.push...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int> nums, int k) {\n int n=nums.size();\n vector<int>ans(n,-1);\n int j=0, i=0;\n long long sum=0;\n while(j<n){\n sum +=nums[j];\n if(j-i+1<2*k+1){\n j++;\n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n \n int totalSize = k+k+1;\n int N = nums.size();\n \n vector<int> answer(N,-1);\n queue<int> numbers;\n long long sum = 0;\n \n if(k >= N){\n \n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> ans(n, -1);\n\n if (k > n / 2)\n return ans;\n\n queue<int> q; \n\n int start = k * 2;\n long sum = 0;\n \n for(int i ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<int> ans;\n if(2*k+1>nums.size()){\n return vector<int>(nums.size(),-1);\n }\n if(k==0){\n return nums;\n }\n int n=nums.size();\n for(int i=0;i...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n = nums.size() ;\n long long csum = 0 ;\n vector<int>ans ;\n int l = 0 ;\n int r = 0 ;\n\n if ( 2*k+1 > n )\n return vector<int>(n,-1) ;\n \n for ( in...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n = nums.size() ;\n long long csum = 0 ;\n vector<int>ans ;\n int l = 0 ;\n int r = 0 ;\n\n if ( 2*k+1 > n )\n return vector<int>(n,-1) ;\n \n for ( in...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n = nums.size() ;\n long long csum = 0 ;\n vector<int>ans ;\n int l = 0 ;\n int r = 0 ;\n\n if ( 2*k+1 > n )\n return vector<int>(n,-1) ;\n \n for ( in...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n \n int n = nums.size();\n if(n < 2*k+1)\n {\n vector<int>temp(n,-1);\n return temp;\n }\n\n vector<int>ans;\n long long frange = 2*k;\n long lon...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n = nums.size() ;\n long long csum = 0 ;\n vector<int>ans ;\n int l = 0 ;\n int r = 0 ;\n\n if ( 2*k+1 > n )\n return vector<int>(n,-1) ;\n \n for ( in...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n if(nums.size()<=2*k){\n vector<int>ans(nums.size(),-1);\n return ans;\n }\n vector<int>ans;\n for(int i=0;i<k;i++){\n ans.push_back(-1);\n }\n long...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n ios_base::sync_with_stdio(false); cin.tie(0);\n //NOTE. ban dau push k con -1 vao, ti nua phai push k con -1 nua\n if (nums.size()<2*k+1) return vector<int> (nums.size(), -1);\n vector<int> ans(...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n ios_base::sync_with_stdio(false); cin.tie(0);\n //NOTE. ban dau push k con -1 vao, ti nua phai push k con -1 nua\n if (nums.size()<2*k+1) return vector<int> (nums.size(), -1);\n vector<int> ans(...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n // requires a full window, else -1\n // so start at k, end at n - k\n // rolling window, adjust total per iter\n \n if (k == 0) {\n return nums;\n }\n \n s...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n if(k==0){\n return nums;\n }\n int n=nums.size();\n int i=0;\n int j=0;\n long long presum=0;\n vector<int> ans;\n while(j<n){\n presum+=nums[j...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int windowSize = 2*k+1, n = nums.size();\n if(n <= windowSize && k>1) {\n vector<int> ans(n, -1);\n return ans;\n } \n \n vector<int> ans(k, -1);\n long long ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n \n vector<int> result;\n int win_len = 2*k+1;\n if(!(2*k+1 <= nums.size())) \n {\n result.insert(result.begin(), nums.size(), -1);\n return result; \n }\n\...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "#define ll long long\n\nclass Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<int>ans;\n int n=nums.size(),l=0;\n ll sum=0;\n if(2*k+1>n){\n for(int i=0;i<n;i++){\n ans.push_back(-1);\n }\n ret...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<int> ans;\n int i = 0,t = k+k+1, n = nums.size();\n while(i<k&&i<n){\n ans.push_back(-1);\n i++;\n }\n long long winsum = 0;\n for(int j = 0; j<t && j<...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<int> ans;\n int i = 0,t = k+k+1, n = nums.size();\n while(i<k&&i<n){\n ans.push_back(-1);\n i++;\n }\n long long winsum = 0;\n for(int j = 0; j<t && j<...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n=nums.size();\n if(k==0){\n return nums;\n }\n vector<int>result(n,-1);\n if(n<2*k+1)\n return result;\n vector<long long >prefixsum(n,0);\n prefixsum[0]=...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> result(n, -1);\n \n // Edge case when k is 0, return the nums array itself\n if (k == 0) return nums;\n \n // Edge case when the window si...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n=nums.size();\n\n vector<int> result(n,-1);\n if(k==0){\n return nums;\n }\n if(n<(2*k+1)){\n return result;\n }\n\n vector<long long> prefixsum(n...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> avgVec(n, -1);\n if (k == 0) {\n return nums;\n }\n if (2 * k + 1 > n) {\n return avgVec; // Not enough elements to form any k-rad...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> avgs(n, -1);\n if (n > 2 * k) {\n vector<long> sums(n, 0);\n sums[0] = nums[0];\n \n for (int i = 1; i < n; i++) {\n sums[i] = ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> avgs(n ,-1);\n if (2*k+1 >n){\n return avgs;\n }\n \n vector<long long> prefix (n,0);\n prefix[0] = nums[0];\n for (int ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n if (k == 0) {\n return nums;\n }\n\n int n = nums.size();\n vector<unsigned long long> prefix(n + 1);\n vector<int> result(n, -1);\n\n // no index will have 'k' radius i...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n // so for every index < i-k and > k+i is -1\n if(k == 0) return nums;\n int n = nums.size();\n vector<int> res(n, -1);\n vector<long long> prefixSum(n, 0);\n prefixSum[0] = nums[0]...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n if (k == 0) {\n return nums;\n }\n\n int n = nums.size();\n vector<unsigned long long> prefix(n + 1);\n vector<int> result(n, -1);\n\n // no index will have 'k' radius i...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n = nums.size(); \n vector<int>ans;\n long long pre[n], suff[n];\n\n pre[0] = nums[0];\n for(int i = 1; i<n; i++){\n pre[i] = pre[i-1] + nums[i];\n }\n\n suff...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n\n // [7,4,3,9,1,8,5,2,6] and k = 3\n // n = 9, o/p = 9.\n // divide by 2k+1 \n // sum of 2k+1 numbers-> preSum[2k+1 elements]\n // pivot -> pivot-k>0 and pivot+k<n -> i(+/-)(2k+1)\n // take avg when above satisfies (ps[pivot+k] - ps[pivot-k])/2k+1\n // [-1,-...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n\n // [7,4,3,9,1,8,5,2,6] and k = 3\n // n = 9, o/p = 9.\n // divide by 2k+1 \n // sum of 2k+1 numbers-> preSum[2k+1 elements]\n // pivot -> pivot-k>0 and pivot+k<n -> i(+/-)(2k+1)\n // take avg when above satisfies (ps[pivot+k] - ps[pivot-k])/2k+1\n // [-1,-...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<long long> prefixArray(nums.size(), 0);\n\nint n = nums.size();\nprefixArray[0] = nums[0];\n//7,4,3,9,1,8,5,2,6\n//7,11,14,23,24,32,37,39,45\nfor (int i = 1; i < n; i++)\n{\n\tprefixArray[i] = prefixArray[i-1...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
2
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<int> averages(nums.size(), -1);\n vector<long> prefixSum(nums.size() + 1, 0);\n const int divisor = (k << 1) + 1;\n \n for (int i = 0; i < nums.size(); ++i) {\n prefixSu...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n long long n=nums.size();\n vector<int> ans(n,-1);\n vector<long long> pre(n);\n if(k>n) return ans;\n if(k==0) return nums;\n pre[0]=nums[0];\n for(int i=1;i<n;i++){...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n long long n=nums.size();\n vector<int> ans(n,-1);\n vector<long long> pre(n);\n if(k>n) return ans;\n if(k==0) return nums;\n pre[0]=nums[0];\n for(int i=1;i<n;i++){...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n = nums.size();\n vector<long long> prefix(n);\n vector<int> avgs(n, -1);\n \n if(n < (2*k - 1))\n return avgs;\n \n if(k == 0)\n return nums;\n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n=nums.size();\n if(n<=k)\n {\n vector<int> ans(n,-1);\n return ans;\n }\n vector<long long> pref(n);\n for(int i=0;i<n;i++)\n {\n if(i=...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<int> ans;\n int sum = 0;\n if(k == 0)\n return nums;\n int n = nums.size();\n vector<long long int> pre(n, 0);\n pre[0] = nums[0];\n for(int i = 1; i < n; ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& v, int k) {\n int len=2*k+1;\n int n=v.size();\n if(k==0){\n return v;\n }\n vector<int>ans;\n vector<long long>pre(n);\n pre[0]=v[0];\n for(int i=1;i<n;i++){\n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n\n \n vector<int> getAverages(vector<int>& nums, int k) {\n vector<int>avgs;\n int n = nums.size();\n\n vector<long long>pref(n);\n \n pref[0]=nums[0];\n for(int i = 1; i < n; i++){\n pref[i] = nums[i] + pref[i-1];\n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n\n vector<int> ans; \n\n // prefixSum array \n vector<long long> prefixSum(nums.size(), 0);\n\n // pre-processing: build the prefix Sum\n prefixSum[0] = nums[0]; \n\n for (int i = 1...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n \n // if k = 0 avg is the original / input array\n if(0 == k) return nums;\n\n int len = nums.size();\n vector<int> ans(len, -1);\n \n // It is possible that the sum...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n \n if(k < 1){\n return nums;\n }else if((k*2+1) > nums.size()){\n vector<int> ans(nums.size(), -1);\n \n return ans;\n }\n \n vector<lon...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n \n // if k = 0 avg is the original / input array\n if(0 == k) return nums;\n\n int len = nums.size();\n vector<int> ans(len, -1);\n \n // It is possible that the sum...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n \n // if k = 0 avg is the original / input array\n if(0 == k) return nums;\n\n int len = nums.size();\n vector<int> ans(len, -1);\n \n // It is possible that the sum...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<int > averages(nums.size(), -1);\n if(k == 0) {\n return nums;\n }\n \n int windowSize = 2*k + 1;\n \n if(windowSize > nums.size()) {\n return a...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n \n vector<int> ans(nums.size(), -1);\n \n // It is possible that the sum of all the elements does not fit in a 32-bit integer type.\n vector<long long> sums;\n long long cu...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n \n vector<int> ans(nums.size(), -1);\n vector<long long> sums;\n long long currSum = 0;\n \n // if k = 0 avg is the original / input array\n if(0 == k) return nums;\n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n \n vector<int> ans(nums.size(), -1);\n vector<long long> sums;\n\n // int can't hold the sum of all elements\n long long currSum = 0;\n\n // window size is defined as the length of...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n long long sum = 0;\n int n = nums.size();\n int windowSize = k * 2 + 1;\n vector<int> averages(n, -1);\n\n if(k == 0) return nums;\n\n if(windowSize > n) return averages;\n\n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n long long sum = 0;\n int n = nums.size();\n int windowSize = k * 2 + 1;\n vector<int> averages(n, -1);\n\n if(k == 0) return nums;\n\n if(windowSize > n) return averages;\n\n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n = nums.size();\n \n \n if(k == 0) return nums;\n \n vector<int> ans(n, -1);\n if (n < 2 * k + 1) return vector<int>(n, -1);\n \n \n vector<lon...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n = nums.size();\n \n \n if(k == 0) return nums;\n \n vector<int> ans(n, -1);\n if (n < 2 * k + 1) return vector<int>(n, -1);\n \n \n vector<lon...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<int> ans;\n long long sum=0;\n\n int i=0,j=0;\n while(i<=j && j<nums.size()){\n sum+=nums[j];\n\n while(j-i+1 > (2*k +1)){\n sum = sum - nums[i];\n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\nprivate:\n bool validIdx(int idx, int n) {\n return idx >= 0 && idx < n;\n } \npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> res(n, -1);\n\n vector<long long> pref(n, 0);\n pref[0] = nums[0...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n = nums.size();\n vector<long long> pref(n, 0), suff(n, 0); // Use long long to avoid overflow\n\n // Build prefix sum array\n pref[0] = nums[0];\n for (int i = 1; i < n; i++) {\n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n=nums.size();\n vector<long long> prek(n);\n long long sum=0;\n for(int i=0;i<n;i++){\n sum+=nums[i];\n if(i-k-1>=0)sum-=nums[i-k-1];\n prek[i]=sum;\n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n = nums.size();\n vector<long long> pre(n, 0), suf(n, 0);\n pre[0] = nums[0];\n suf[n-1] = nums[n-1];\n for(int i = 1; i < n; i++) {\n pre[i] = nums[i] + pre[i-1];\n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n=nums.size();\n vector<long long >prefix(n,0);\n vector<long long>suffix(n,0);\n long long sum=0;\n for(int i=0;i<n;i++){\nsum+=nums[i];\nprefix[i]=sum;\n\n }\nsum=0;\n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n=nums.size();\n vector<int>ans(n,-1);\n\n if(nums.size() <= (2*k))\n {\n return ans;\n } \n else\n {\n int right=0, left=0;\n vector<long long> sum;\n sum.push_back(nu...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n int n=nums.size();\n vector<int>ans(n,-1);\n\n if(nums.size() <= (2*k))\n {\n return ans;\n } \n else\n {\n int right=0, left=0;\n vector<long long> sum;\n sum.push_back(nu...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<long long >sum;\n if(k==0)\n return nums;\n \n long long acc=0;\n for(int i=0;i<nums.size();i++){\n acc=acc+nums[i];\n sum.push_back(acc);\n }\n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n \n if (k == 0) {\n return nums;\n }\n \n int n = nums.size();\n std::vector<long> prefix = {nums[0]};\n for (int i = 1; i < n; i++) {\n prefix.push_bac...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n \n if (k==0)\n {\n return nums; // average of every single element is just itself\n }\n \n int n = nums.size();\n \n int den...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<int> result(nums.size(), -1);\n if( k == 0) return nums;\n\n vector<long> prefixSum { nums[0]};\n for(int i = 1 ; i < nums.size(); ++i)\n {\n prefixSum.push_back(prefix...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n \n if(k < 1){\n\n return nums;\n }else if((k*2+1) > nums.size()){\n vector<int> ans(nums.size(), -1);\n \n return ans;\n }\n \n vector<l...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<long long> sums;\n \n sums.push_back(0);\n int div = 2*k+1;\n \n for (int i = 0; i < nums.size(); i++) {\n sums.push_back(nums[i] + sums[i]);\n }\n ...