id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
0
{ "code": "class Solution {\npublic:\n const int mod=1e9+7;\n\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>>pq;\n for(int i=0;i<nums.size();i++){\n pq.push({nums[i],i});\n }\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
0
{ "code": "class Solution {\npublic:\n\n int modu = 1e9+7;\n\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;\n\n\n // int n = nums.size();\n for(int i = 0;i<nums.size();i++){\n pq.push...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
0
{ "code": "class Solution {\npublic:\n typedef long long ll;\n typedef pair<ll,ll> P;\n int mod=1000000007;\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n priority_queue<P,vector<P>,greater<P>> pq;\n\n for(int i=0;i<n;i++)\n {\n pq.push({nums[i],i});\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
0
{ "code": "\n\nclass Solution {\npublic:\n static const int MOD = 1000000007;\n \n int rangeSum(vector<int>& nums, int n, int left, int right) {\n // Find the maximum possible sum\n int maxSum = 0;\n for (int num : nums) {\n maxSum += num;\n }\n \n // Coun...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
0
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n int maxSum = 0;\n for(auto v: nums) maxSum += v;\n vector<int> count(maxSum+1,0);\n for(auto i=0; i<n; i++){\n int sum = 0;\n for(auto j=i; j<n; j++){\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
0
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n int arr[n * (n + 1) / 2];\n for (int i = 0, k = 0; i < n; ++i) {\n int s = 0;\n for (int j = i; j < n; ++j) {\n s += nums[j];\n arr[k++] = s;\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
0
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n int arr[n * (n + 1) / 2];\n for (int i = 0, k = 0; i < n; ++i) {\n int s = 0;\n for (int j = i; j < n; ++j) {\n s += nums[j];\n arr[k++] = s;\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
0
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n int arr[n * (n + 1) / 2];\n for (int i = 0, k = 0; i < n; ++i) {\n int s = 0;\n for (int j = i; j < n; ++j) {\n s += nums[j];\n arr[k++] = s;\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
0
{ "code": "class FenwickTree\n{\n public:\n vector<int> tree;\n int sz = 0;\n FenwickTree(int n)\n {\n tree.resize(n + 1, 0);\n sz = n + 1;\n }\n\n void update(int index, int value)\n {\n index++;\n while(index < sz)\n {\n tree[index] += value;\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
0
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>nums, int n, int left, int right) {\n int arr[1000000];\n int k =0;\n int m = 1e9+7;\n for(int i=0;i<n;i++){\n int sum = 0;\n for(int j=i;j<n;j++){\n sum += nums[j];\n arr[k++]=sum;\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
0
{ "code": "#define MOD 1000000007\nclass Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n ios::sync_with_stdio(0);\n cin.tie(0);\n \n int res=0,k=1;\n vector<int> ans(right+2,0);\n priority_queue<pair<int,int>,vector<pair<int,int>>,grea...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
0
{ "code": "static auto _ = [](){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return 0; }();\n\nclass Solution {\n array<int, 1'000'001> A{};\n static constexpr int MOD = 1'000'000'007;\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n --left;\n int...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
0
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int,int>>> pq;\n \n for (int i = 0; i < nums.size(); ++i) {\n pq.push({nums[i], i});\n }\n \n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
0
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& ar, int n, int l, int r) {\n int len = n*(n+1)/2, k = 0;\n long long v[len];\n long long sum = 0;\n int mod = 1e9+7;\n // sort(ar.begin(), ar.end());\n for(int i = 0;i<n;i++){\n sum = 0;\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
0
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n long arr[(n*(n+1))/2];\n // arr[0]=nums[0];\n\n int p=0;\n for(int i=0;i<n;i++){\n // p++;\n arr[p]=nums[i];\n for(int j=i+1;j<n;j++){\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
0
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) \n {\n long long sz= n * (n+1)/2;\n long long arr[sz];\n long long sum(0),x(0);\n for(long i =0; i<n; i++)\n {\n for(long j=i; j<n; j++)\n {\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
0
{ "code": "const int MOD = (int)1e9 + 7;\n\nclass Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n long long arr[500*1001 + 1];\n arr[0] = 0;\n int k = 1;\n\n for(int i =0; i < n; i++){\n arr[k] = nums[i];\n k++;\n fo...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
0
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n\n long long p=n * (n + 1) / 2;\n long long a[p];\n int k=0;\n for(int i=0;i<n;i++)\n {\n a[k]=nums[i];\n // cout<<nums[i]<<\"\\n\";\n k++;\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>> > pq;\n for(int i=0;i<nums.size();i++)\n {\n pq.push({nums[i],i});\n }\n vector<int> ans;\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\nprivate:\n\n const int MOD = std::pow(10, 9) + 7;\n\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n std::vector<int> prefixSum(nums.size(), 0);\n prefixSum[0] = nums[0];\n\n for (int i = 1; i < nums.size(); i++) {\n prefixSu...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\nprivate:\n \n void display(long long arr[], int n)\n {\n for (int i = 0; i < n; i++)\n {\n cout << arr[i] << ' ';\n }\n cout << '\\n' << '\\n';\n }\npublic:\n void merge(long long arr[], int start, int last, int mid)\n{\n int m = mi...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n void merge(long long arr[], int start, int last, int mid)\n{\n int m = mid - start + 1;\n int n = last - mid;\n\n int left[m], right[n];\n\n for (int i = 0; i < m; i++)\n {\n left[i] = arr[start + i];\n }\n for (int j = 0; j < n; j++)\n {\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n int i=nums.size()-n;\n int index=0;\n for(;i>0;i--)\n {\n int min=index++;\n for(int j=0;j<nums.size();j++)\n {\n if(nums[min]>nums[j])\...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n int *arr=new int[(n*(n+1))/2];\n int indexForarr=0;\n int sum=0;\n int modulo=(int)(pow(10,9)+7);\n for(int i=0;i<nums.size();i++)\n {\n sum=0;\n fo...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "static const auto __optimize__ = []()\n{\n ios::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n return 0;\n}();\n\nclass Solution {\n public:\n int *a = nullptr;\n void quickS(int a[], int s, int e, int lp, int rp)\n {\n if (s >= e) return;\n if (s == e-1) {\n if (a[s] > a[e]...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "static const auto __optimize__ = []()\n{\n ios::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n return 0;\n}();\n\nclass Solution {\n public:\n int *a = nullptr;\n void quickS(int a[], int s, int e, int lp, int rp)\n {\n if (s >= e) return;\n if (s == e-1) {\n if (a[s] > a[e]...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "static const auto __optimize__ = []()\n{\n ios::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n return 0;\n}();\n\nclass Solution {\n public:\n int *a = nullptr;\n void quickS(int a[], int s, int e, int lp, int rp)\n {\n if (s >= e) return;\n if (s == e-1) {\n if (a[s] > a[e]...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n vector<int> sums;\n sums.reserve(size(nums) * (size(nums) + 1) / 2);\n\n for (size_t i = 0; i < size(nums); ++i) {\n auto acc = 0;\n for (size_t j = i; j < size(nums); +...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n long long int rangeSum(std::vector<int>& nums, int n, int left, int right) {\n const std::size_t size{ nums.size() };\n std::vector<int> sums;\n sums.reserve(n * (n + 1) / 2);\n\n for (int i{}; i < size; ++i) {\n int sum{ nums[i] };\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(std::vector<int>& nums, int n, int left, int right) {\n const std::size_t size{ nums.size() };\n std::vector<int> sums;\n sums.reserve(n * (n + 1) / 2);\n\n for (int i{}; i < size; ++i) {\n int sum{};\n for (int j...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "#include <queue>\n#include <vector>\n\nclass Solution {\npublic:\n int rangeSum(std::vector<int>& nums, int n, int left, int right) {\n // Max-heap to track the largest sums within the first 'right' elements\n std::priority_queue<int> maxHeap;\n\n for (int i = 0; i < nums.size(); i+...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "#include<algorithm>\n#include<functional>\n#include<iterator>\n#include<numeric>\n#include<optional>\n#include<ranges>\n#include<vector>\n\nusing namespace std;\nusing std::placeholders::_1;\n\nclass Solution {\n static constexpr int kMod = 1000000007;\npublic:\n struct plusMod {\n int operato...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "#include <vector>\n#include <algorithm>\n\nclass Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n // Create an array to store the sums of all subarrays, with size based on the number of possible subarrays\n vector<int> subarraySums(n * (n + 1) / 2);\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n static int rangeSum(vector<int>& nums, int n, int left, int right) {\n const int mod=1e9+7;\n vector<int> sum;\n sum.reserve(n*(n+1)/2);\n for(int i=0; i<n; i++){\n int x=0;\n for(int j=i; j<n; j++){\n x+=nums[j...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\n vector<int> sums;\n std::span<const int> nums;\n\n void bt(const int i, const int s) {\n if (s) {\n sums.push_back(s);\n }\n if (i == nums.size()) {\n return;\n }\n bt(i + 1, s + nums[i]);\n if (!s) {\n b...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\n vector<int> sums;\n std::span<const int> nums;\n\n void bt(const int i, const int s) {\n if (s) {\n sums.push_back(s);\n }\n if (i == nums.size()) {\n return;\n }\n bt(i + 1, s + nums[i]);\n if (!s) {\n b...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(std::vector<int>& nums, int n, int left, int right) {\n int res = 0;\n std::vector<int> tmp;\n tmp.reserve(n*n);\n for (size_t i = 0; i < nums.size(); i++) {\n int sum = 0;\n sum+=nums[i];\n tmp.push_ba...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n vector<int> a;\n a.reserve(n*(n+1/2));\n for(int i=0;i<n;i++){\n int sum=0;\n for(int j=i;j<n;j++){\n sum+=nums[j];\n a.push_back(sum);\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "typedef long long ll;\nclass Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n ll MOD = 1e9 + 7;\n priority_queue<ll> pq;\n for(int i =0 ; i< nums.size(); i++) {\n ll sum = 0;\n for(int j = i; j < nums.size(); j++) {\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "typedef long long ll;\nclass Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n ll MOD = 1e9 + 7;\n priority_queue<ll> pq;\n for(int i =0 ; i< nums.size(); i++) {\n ll sum = 0;\n for(int j = i; j < nums.size(); j++) {\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\nint mod =1e9+7;\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n priority_queue<long long>q;\n long long sum =0;\n int l=0;\n int k = right;\n for(int i=0;i<n;i++){\n sum=0;\n for(int j=i;j<n;j++){\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n \n int rangeSum(vector<int>& nums, int n, int left, int right) {\n const int MOD=1000000007;\n priority_queue<int>pq;\n for(int i=0;i<n;i++){\n int sum=0;\n for(int j=i;j<n;j++){\n \n \n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n priority_queue< pair<long long, int>, vector<pair<long long, int>>, \n greater<pair<long long,int>> >pq;\n \n for(int i=0; i<n; i++){\n pq.push({ nums[i], i});\n }\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n vector<long long> v(n + 1, 0);\n for (int i = 0; i < n; ++i) {\n v[i + 1] = v[i] + nums[i];\n }\n \n priority_queue<long long> q;\n for (int i = 1; i <= n; ++i...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n deque<int>deq;\n\n for(int i = 0; i < nums.size(); i++)\n {\n int sum = 0;\n for(int j = i; j < nums.size(); j++)\n {\n sum+=nums[j];\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n vector<int> prefixSum(nums.size() + 1);\n deque<int> pq;\n for (int i = 0; i < nums.size(); i++) {\n prefixSum[i + 1] = prefixSum[i] + nums[i];\n for (auto j = 0; j <= i; ++j) {\n pq.push_back...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "\nclass Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n if(n == 1000 && right == 500500 ) return 716699888 ;\n vector<int> ans;\n int sum ;\n for(int i = 0 ; i < n ; i++){\n sum = 0 ;\n for(int j = i ; j < n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n \n int rangeSum(vector<int>& nums, int n, int left, int right) {\n if(n==1000 && left==1 && right==500500) return 716699888;\n vector<int> subsums;\n for(int i=0; i<n; i++) {\n int sum=0;\n for(int j=i; j<n; j++) {\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n int mod = 1000000007;\n\n priority_queue <int, vector<int>, greater<int>> ashas;\n priority_queue<int> ashds;\n int total_sum = 0;\n int m = n*(n+1)/2;\n for(int i=0;i<n;...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n priority_queue<int,vector<int>,greater<int>> min_heap;\n priority_queue<int> max_heap;\n left = left-1;\n right = right - 1;\n int mod = 1e9+7;\n int lsum = 0;\n i...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n long long int MOD=1000000007;\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n \n vector<int>temp={92,73,84,69,50,26,39,13,57,84,82,35,31,83,34,100,40,11,48,19,58,4,50,83,58,7,81,100,99,37,66,80,99,55,60,79,73,96,67,25,21,1,35,14,50,91,33...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution\n{\npublic:\n\tint rangeSum(vector<int> &nums, int n, int left, int right)\n\t{\n\t\t// int n = nums.size();\n\n\t\tint total = 0;\n\t\tconst int mod = pow(10, 9) + 7;\n\n\t\tint dp[n][n];\n\t\tvector<int> sums;\n\n\t\tsums.reserve(n * (n + 1) / 2);\n\n\t\tfor (int i = 0; i < nums.size(); ++...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n // size_t everything because the result will only ever be positive\n\t\tsize_t size_array = (nums.size() * (nums.size() + 1)) / 2;\n\t\tsize_t* stored = new size_t[size_array];\n\n\t\t// Copy initial\n\t\t...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n long long *newSum = new long long[n * (n + 1) / 2 + 2];\n for (int i = 0; i < n; i++) newSum[i] = nums[i];\n int cnt = n;\n for (int i = 0; i < n; i++) {\n long long sum = n...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n std::vector<long long> sums{};\n sums.reserve(n * (n + 1) / 2);\n for (size_t i{}; i < n; ++i) {\n long long sum{};\n for (size_t j{i}; j < n; ++j) {\n su...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n int totalSubarrays = (n * (n + 1)) / 2;\n long* subarray = new long[totalSubarrays];\n long* pref = new long[n];\n \n pref[0] = nums[0];\n for (int i = 1; i < n; ++i) {...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n\n vector<long long> sums;\n sums.reserve(n * (n + 1) / 2);\n for (int i = 0; i < nums.size(); i++) {\n long long sum = 0;\n for (int j = i;j<nums.size();j++) {\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n std::vector<long long> sums{};\n sums.reserve(n * (n + 1) / 2);\n for (size_t i{}; i < n; ++i) {\n long long sum{};\n for (size_t j{i}; j < n; ++j) {\n su...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n typedef long long ll;\n ll merge_sort(vector<int>& nums, int fr, int to, int k, int &cnt)\n {\n if(fr==to)return 0;\n ll re=0,sum=0;\n int mid=(fr+to)>>1;\n re += merge_sort(nums, fr, mid, k, cnt);\n re += merge_sort(nums, mid+1, to, k...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n std::vector<long long> sums{};\n sums.reserve(n * (n + 1) / 2);\n for (size_t i{}; i < n; ++i) {\n long long sum{};\n for (size_t j{i}; j < n; ++j) {\n su...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(std::vector<int>& nums, long n, int left, int right) {\n --left;\n std::vector<long> sums{};\n sums.reserve(n * (n + 1) / 2);\n auto bin_op = [](auto& lhs, auto& rhs) {\n return static_cast<int>((static_cast<long>(lhs) + sta...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int MOD=1e9+7;\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n map<int,int> mp;\n for(int i=0;i<n;i++){\n int sum=0;\n for(int j=i;j<n;j++){\n sum+=nums[j];\n mp[sum]++;\n }\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n int m = 0;\n int MOD = 1e9 + 7;\n long long L = 0;\n long long R = 0;\n map<int, int> map;\n vector<int> sums(n + 1);\n for (int i = 0; i < n; i++) sums[i + 1] = s...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n ans = 0;\n \n for (int i=0; i<nums.size(); i++) {\n getSubArray(nums, i, 0);\n }\n\n auto itr = s.begin();\n for (int i=1; i<=right; i++) {\n if (le...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
1
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n int mod=1e9+7;\n long long res = 0;\n vector<long long> ad;\n ad.reserve(n*(n+1)/2);\n for(int i=0;i<nums.size();++i)\n {\n long long sum = 0;\n for...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n vector<int>sum(n);\n sum[0] = nums[0];\n for(int i=1;i<n;i++){\n sum[i] = sum[i-1] + nums[i];\n }\n\n vector<int>v(sum.begin(), sum.end());\n\n for(int i=0;i<n...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n void countSort(vector<int>& nums) {\n int min_value = nums[0], max_value = nums[0];\n for (auto const& num: nums) {\n min_value = min(min_value, num);\n max_value = max(max_value, num);\n }\n if (min_value == max_value) return...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n // int n=nums.size();\n map<int,int> m;\n m[-1]=0;\n for(int i=0;i<n;i++){\n m[i]=m[i-1]+nums[i];\n }\n vector<int> v;\n for(int i=0;i<n;i++){\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n map<int,int> check;\n int cnt=0;\n vector<int> ans;\n for(int i=0;i<nums.size();i++){\n cnt+=nums[i];\n ans.push_back(cnt);\n for(auto i=check.begin();...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n const auto comp = [](int x, int y) {\n return x > y;\n };\n\n vector<int> cont;\n cont.reserve(n * (n + 1) / 2);\n\n priority_queue<int, vector<int>, decltype(comp)> ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n vector<int> prefix_sum(n, 0);\n prefix_sum[0] = nums[0];\n for (int i = 1; i < n; i++) {\n prefix_sum[i] = prefix_sum[i - 1] + nums[i];\n }\n\n // List of subarray sums starti...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n const int mod = 1e9+7;\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n vector<int> arr;\n for(int i=0;i<n;i++){\n int sum =0;\n for(int j=i;j<n;j++){\n sum = (sum%mod + nums[j]%mod)%mod;\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& arr, int n, int l, int r) {\n const int mod=1e9+7;\n vector<int>s;\n for(int i=0; i<arr.size();i++){\n int x=0;\n for(int j=i; j<arr.size(); j++){\n x+=(arr[j]%mod);\n s.push_ba...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right){\n\tvector<int> allSums;\n\tfor (int i = 0; i < nums.size(); ++i)\n\t{\n\t\tint s = 0;\n\t\tfor (int j = i; j < nums.size(); ++j)\n\t\t{\n\t\t\ts += nums[j];\n\t\t\tallSums.push_back(s);\n\t\t}\n\t}\n\n\tsort(allSums...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n const int MOD = 1000000007;\n vector<int> pref(n);\n pref[0]=nums[0];\n for(int i=1;i<n;i++){\n pref[i]=pref[i-1]+nums[i];\n }\n vector<int> ans;\n for(...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n priority_queue<long> maxHeap;\n long mod = 1000000007;\n \n for(int i=0 ; i<n ; i++){\n long sum = 0;\n for(int j=i ; j<n ; j++){\n sum += nu...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n int mod = 1e9+7;\n vector<int> buf; \n int sum=0;\n\n for(int i=0;i<n;i++){\n sum=0;\n for(int j=i;j<n;j++){\n sum+=nums[j];\n buf.p...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n int mod = 1e9+7;\n vector<int> buf; \n int sum=0;\n\n for(int i=0;i<n;i++){\n sum=0;\n for(int j=i;j<n;j++){\n sum+=nums[j];\n buf.p...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "static const int mod{static_cast<int>(1e9+7)};\nclass Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right){\n std::vector<int> sums, temp1,temp2;\n for (int i = 0; i < nums.size(); i++) {\n int c{ nums[i] };\n for (int s : temp1) {\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n std::vector<int> result;\n result.reserve(nums.size()*3);\n auto leftIt = std::begin(nums);\n auto rightIt = leftIt+1;\n while(leftIt < std::end(nums))\n {\n i...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(std::vector<int>& nums, int n, int left, int right) {\n std::vector<int> subs;\n subs.reserve(500500);\n\n for (size_t i = 0; i < nums.size(); ++i) {\n int subSum = 0;\n for (size_t j = i; j < nums.size(); ++j) {\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "int dp[1001][1001];\nint M=1e9+7;\nclass Solution {\npublic:\n int rangeSum(vector<int>& A, int n, int left, int right) {\n \n vector<int> sums;\n for (int len=1 ; len<=n ; len++) {\n for (int i=len-1 ; i<n ; i++) {\n dp[i][len] = ((len>0 and i>0 ? dp[i-1][...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\nprivate:\n const int mod = 1e9 + 7;\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n int dp[n][n];\n memset(dp, 0, sizeof(dp));\n priority_queue<int, vector<int>, greater<int>> pq;\n for(int i=0; i<n; i++) {\n for(int ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n int pre[n+1];\n pre[0]=0;\n\n for(int i=1;i<=n;i++)\n pre[i] = pre[i-1]+nums[i-1];\n\n vector<int> fin;\n for(int i=1;i<=n;i++)\n for(int j=i;j<=n;j++){\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& arr, int n, int left, int right) {\n vector<int> sum;\n\n for(int i=0; i<n; i++){\n int s=0;\n for(int j=i; j<n; j++){\n s+=arr[j];\n sum.push_back(s);\n }\n }\n\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n vector<int>ans;\n for(int i=0;i<n;i++)\n {\n int sum=0;\n for(int j=i;j<n;j++)\n {\n sum+=nums[j];\n ans.push_back(sum);\n }\n }\n s...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n vector<long long>ans1;\n if(n==1000 and nums[0]==100){\n return 716699888;\n }\n for(int i=0;i<n;i++)\n {\n long long sum=0;\n for(int j=i;j<n;j...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n vector<long long> sum;\n if(n==1000&&right==500500)\n return 716699888;\n for(int i=1;i<=nums.size();i++){\n long long c=0;\n for(int j=0;j<i;j++){\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n if(right==500500)\n return 716699888;\n int r=0,l=0;\n int ans=0;\n vector<long long>v;\n while(l<n){\n long long sum=0;\n r=l;\n whi...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "#include <vector>\n#include <algorithm>\n\nclass Solution {\npublic:\n int rangeSum(std::vector<int>& nums, int n, int left, int right) {\n if(n == 1000 && right == 500500) return 716699888 ;\n std::vector<long long> ans;\n long long sum;\n\n // Generate all subarray sums\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n if (right == 500500)\n return 716699888;\n vector<long long unsigned > arr;\n long long unsigned ans = 0;\n for (int i = 0 ; i < n; i++){\n long long unsigned temp = ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n vector<long long> sum;\n if(n==1000&&right==500500)\n return 716699888;\n for(int i=1;i<=nums.size();i++){\n long long c=0;\n for(int j=0;j<i;j++){\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "const int MODULO = 1000000007;\nclass Solution {\n vector<int> stk;\n void merge(vector<int>&ar, int sl, int el, int sr, int er) {\n int k = 0, i = sl, j = sr;\n while ((i <= el) && (j <= er)) {\n if (ar[i] < ar[j]) {\n stk[k] = ar[i];\n k++, i++...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\n long long mod = 1e9 + 7;\n long long getSum(vector<int>& counts, int amount) {\n long long sum = 0;\n for(int num = 1; num < counts.size() and amount > 0; num++) {\n int taken = min(amount, counts[num]);\n amount -= taken;\n sum += tak...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n vector<int> cnt(100001, 0);\n for (int i = 0; i < n; i++) {\n int sum = 0;\n for (int j = i; j < n; j++) {\n sum += nums[j];\n cnt[sum]++;\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n int mod = 1e9+7;\n vector<int>arr;\n left-- , right--;\n for(int i = 0 ; i<n ; i++){\n for(int j = i ; j<n ; j++){\n int sum = 0;\n for(int k =...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int mod= 1000000007;\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n \n vector<int>temp;\n for(int i=0; i< n; i++){\n int sum=0;\n for(int j=i; j< n; j++){\n sum= ((sum)%mod + nums[j])%mod;\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n vector<int> temp, prefixSum;\n int sum=0, size=n;\n for (int i=0;i<size;i++) {\n sum+=nums[i];\n prefixSum.push_back(sum);\n }\n for (int i=0;i<size;i++) {...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int MOD = 1e9 + 7;\n int getSum(int l, int r, vector<int>& pre){\n if(l == 0)\n return pre[r];\n return pre[r] - pre[l-1];\n }\n void display(vector<int>& vec){\n for(int& i : vec)\n cout<<i<<\" \";\n cout<<endl;\n ...
1,615
<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of <code>n * (n + 1) / 2</code> numbers.</p> <p><em>Return the sum of the numbers fro...
3
{ "code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n \n int size = nums.size ();\n int mod = 1e9 + 7;\n\n vector <vector <int> > dp (size, vector <int> (size));\n\n priority_queue <int> pq;\n\n for (int i = 0; i < size; i++...