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... | 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++... |
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> newNums;\n for(int i=0;i<nums.size();i++){\n vector<int> b(nums.size() - i);\n partial_sum(nums.begin()+i,nums.end(),b.begin());\n for(auto n:b) newNums.... |
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> newNums;\n for(int i=0;i<nums.size();i++){\n vector<int> b(nums.size() - i);\n partial_sum(nums.begin()+i,nums.end(),b.begin());\n for(auto n:b) newNums.... |
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<int, vector<int>, greater<int>>pq;\n vector<int>v1, v2;\n for (auto &n : nums) {\n v1 = {n};\n for (auto &m : v2) {\n v1.push_back(n + m);\... |
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>ans;\n queue<int>q;\n for(int i=0;i<n;i++){\n for(int j=i;j<n;j++){\n q.push(nums[j]);\n }\n int cnt=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... | 3 | {
"code": "class Solution {\npublic:\n const int MOD = pow(10, 9) + 7;\n\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n queue<int> q;\n priority_queue<int, vector<int>, greater<int>> transform;\n int sum = 0;\n\n for (int i=0; i<n; i++) {\n sum = (sum + ... |
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> arr;\n int M=1000000007;\n queue<int> q;\n for(int i=0;i<n;i++){\n int sz=q.size();\n while(sz--){\n int u=q.front();\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 subarr(vector<int> &nums,vector<int> &sums,int i,queue<int> &q)\n {\n if(nums.size()-1==i)\n {\n cout<<nums[i]<<\" \";\n sums.push_back(nums[i]);\n q.push(nums[i]);\n return;\n }\n subarr(nums,sum... |
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<vector<int>> vvi(n);\n int i, j;\n int mod = 1e9 + 7;\n vvi[0].push_back(nums[0]);\n for(i = 1; i < n; i++) {\n nums[i] = nums[i] + nums[i - 1];\n v... |
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 size=(n*(n+1))/2;\n int mod=1e9+7;\n vector<vector<int>> pf(n,vector<int>(n,-1));\n vector<int> tmp(size,0);\n int idx=1;\n tmp[0]=pf[0][0]=nums[0];\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": "static const int modder = []()\n{\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 1e9 + 7;\n}();\n\nclass Solution\n{\npublic:\n int memoize(vector<vector<int>>& memoizer, vector<int>& nums, int low, int high)\n {\n if (memoizer[low][high] != 0... |
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 size=(n*(n+1))/2;\n int mod=1e9+7;\n vector<vector<int>> pf(n,vector<int>(n,-1));\n vector<int> tmp(size,0);\n int idx=1;\n tmp[0]=pf[0][0]=nums[0];\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 unordered_set<int> diff;\n unordered_map<int, int> mp;\n for(int left = 0; left < n; left++){\n for(int right = left; right < n; right++){\n int num = 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... | 3 | {
"code": "class Solution {\npublic:\n const int MOD = 1000000007;\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n vector<int> curr;\n vector<int> last;\n vector<int> finall;\n for(auto i : nums)\n {\n for(auto j : last)\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 priority_queue<int>pq;\n long long mod=1e9+7;\n queue<int>q;\n for(int i=0;i<nums.size();i++)\n {\n queue<int>q2;\n pq.push(nums[i]);\n while(!q... |
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 public:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n vector<int> subArraySum;\n\n\n long currSum = 0;\n long sub = 0 ;\n int offSet = nums.size();\n for(int i = 0; i < nums.size(); 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 {\n public:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n vector<int> subArraySum;\n\n for(int i = 0; i < nums.size(); i++) {\n if(i == 0) {\n subArraySum.push_back(nums[i]);\n continue;\... |
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": "#define MOD 1000000007\nclass Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n int answer = 0;\n int finalArray = (n%2==1)?(n*((n+1)/2)):((n/2)*(n+1));\n vector<int>sums(finalArray,0);\n int z = 0 ;\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": "#include <vector>\n#include <unordered_map>\n#include <algorithm>\n\nclass Solution {\npublic:\n int rangeSum(std::vector<int>& nums, int n, int left, int right) {\n std::unordered_map<int, int> sumFreq; // Store sums with their frequencies\n std::vector<int> subarraySums; // Store all sub... |
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 long long rangeSum(vector<int>& nums, int n, int left, int right) {\n long long mod=1e9+7;\n int size=n * (n+1)/2;\n vector<long long>ans(size);\n for(int i=0;i<n;i++){\n ans[i]=nums[i];\n }\n \n //n-1\n long l... |
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 double> arr(n * (n + 1) / 2);\n int k = 0;\n\n for(int i = 0; i < n; i++) {\n long double sum = 0;\n for(int j = i; j < n; j++) {\n sum += (lo... |
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 long long mod = 1e9+7;\n\n long long m=(n*(n+1LL))/2;\n vector<long long> subarrays(m);\n long long sum=0, cnt=0;\n\n for(int i=0;i<n;i++){\n 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 int sz = n * (n + 1) / 2;\n vector<long long> sum(sz), pref(sz);\n int mod = 1e9 + 7;\n int k = 0;\n for (int i = 0; i < n; i++) {\n long long cur = 0;\n f... |
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 long long rangeSum(vector<int>& nums, int n, int left, int right) {\n std::ios::sync_with_stdio(false);\n std::cin.tie(0);\n std::cout.tie(0);\n \n long long mod=1e9+7;\n int size=n * (n+1)/2;\n vector<long long>ans(size);\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 print(const vector<long long>& v, int x) {\n for (int i=0; i<x; i++) {\n cout << v[i] << ' ';\n }\n cout << '[' << x << ']' << ' ';\n for (int i=x+1; i<(int)v.size(); i++) {\n cout << v[i] << ' ';\n }\n cout... |
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 calc(int start, vector<uint64_t> &res) {\n auto last = res.size();\n auto fv = res[start];\n for(auto i = start + 1; i < last; ++i) {\n auto c = res[i] - fv;\n res.push_back(c);\n }\n return last;\n }\n\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... | 3 | {
"code": "class Solution {\npublic:\n int rangeSum(vector<int>& nums, int n, int left, int right) {\n vector<long long>arr;\n for(int i=0;i<nums.size();i++)\n { long long s=0;\n for(int j=i;j<nums.size();j++)\n {\n s=s+nums[j];\n arr.push_... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 0 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n\n int size = nums.size();\n\n if (size < 5) {\n return 0;\n }\n\n if (size < 9) {\n std::sort(nums.begin(), nums.end());\n\n int diff1 = nums.back() - nums[3];\n i... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 0 | {
"code": "class Solution {\npublic:\n static int minDifference(vector<int>& nums) {\n const uint n = nums.size();\n if (n <= 4) return 0;\n const auto beg = nums.begin(), end = nums.end();\n if (n <= 16)\n sort(beg, end);\n else {\n nth_element(beg, beg + 3... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 0 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n //Approach-1 (Using complete sorting)\n //T.C : O(nlogn)\n //S.C : O(1)\n // int n = nums.size();\n // sort(nums.begin(),nums.end());\n\n // if (n<=4) {\n // return 0;\n // }\... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 0 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) \n {\n if(nums.size() <= 4) return 0;\n\n vector<int> greatest_nums{};\n vector<int> smallest_nums{};\n\n int greatest_num_index=1, smallest_num_index=1;\n\n for(int i = 0; i < 4; i++)\n {\n ... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 0 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) \n {\n if(nums.size() <= 4) return 0;\n\n vector<int> greatest_nums{};\n vector<int> smallest_nums{};\n\n int greatest_num_index=1, smallest_num_index=1;\n\n for(int i = 0; i < 4; i++)\n {\n ... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 0 | {
"code": "#pragma GCC optimize(\"Ofast\",\"inline\",\"fast-math\",\"unroll-loops\",\"no-stack-protector\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native\",\"f16c\")\n\nconst auto init = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(n... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 0 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) \n {\n if(nums.size() <= 4) return 0;\n\n vector<int> greatest_nums{};\n vector<int> smallest_nums{};\n\n int greatest_num_index=1, smallest_num_index=1;\n\n for(int i = 0; i < 4; i++)\n {\n ... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 0 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) \n {\n if(nums.size() <= 4) return 0;\n\n vector<int> greatest_nums{};\n vector<int> smallest_nums{};\n\n int greatest_num_index=1, smallest_num_index=1;\n\n for(int i = 0; i < 4; i++)\n {\n ... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 0 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n int n = nums.size();\n if(n<=4)\n return 0;\n \n partial_sort(nums.begin(), nums.begin()+4, nums.end());\n vector<int> low(nums.begin(),nums.begin()+4);\n partial_sort(nums.begin(), ... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 0 | {
"code": "constexpr int MOVES = 3;\n\nstruct Solution {\n constexpr inline int minDifference(const vector<int>& n) const {\n if (n.size() < MOVES + 2)\n return 0;\n multiset<int> small = {n.front()};\n multiset<int, decltype([](const int a, const int b) { return b < a; })> big = {n... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 0 | {
"code": "constexpr int MOVES = 3;\n\nstruct Solution {\n constexpr inline int minDifference(const vector<int>& n) const {\n if (n.size() < MOVES + 2)\n return 0;\n multiset<int> small = {n.front()};\n multiset<int, decltype([](const int a, const int b) { return b < a; })> big = {n... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 0 | {
"code": "constexpr int MOVES = 3;\n\nstruct Solution {\n constexpr inline int minDifference(const vector<int>& n) const {\n if (n.size() < MOVES + 2)\n return 0;\n multiset<int> small = {n.front()};\n multiset<int, decltype([](const int a, const int b) { return b < a; })> big = {n... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 0 | {
"code": "class Solution {\npublic:\n static int minDifference(vector<int>& nums) {\n const int n=nums.size();\n if (n<=4) return 0;\n priority_queue<int> small;\n priority_queue<int, vector<int>, greater<int>> big;\n for (int x :nums){\n if (small.size()>3){\n ... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 0 | {
"code": "class Solution {\npublic:\n static int minDifference(vector<int>& nums) {\n const int n=nums.size();\n if (n<=4) return 0;\n priority_queue<int> small;\n priority_queue<int, vector<int>, greater<int>> big;\n for (int x :nums){\n if (small.size()>3){\n ... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 0 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n int n=nums.size();\n if(n<=4) return 0;\n sort(nums.begin(),nums.end());\n int a=nums[n-4]-nums[0];\n int b=nums[n-3]-nums[1];\n int c=nums[n-2]-nums[2];\n int d=nums[n-1]-nums[3];\n ... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 0 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n \n int n = nums.size();\n if (n < 5){\n return 0;\n }\n\n sort(nums.begin(), nums.end());\n\n int diff = 0, min_diff = INT_MAX;\n for (int i = 0; i < 4; i++){\n dif... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 0 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n int mini = INT_MAX;\n if(nums.size() <=4){\n return 0;\n }\n else{\n sort(nums.begin(), nums.end());\n int gap = nums.size() -4;\n vector<int> diff;\n f... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 0 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n int n = nums.size();\n if(n <= 4){\n return 0;\n }\n sort(nums.begin(),nums.end());\n int ws = n-3;\n int i = 0;\n int j = 1;\n int ans = INT_MAX;\n while(j < n)... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 0 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n //Approach-1 (Using complete sorting)\n //T.C : O(nlogn)\n //S.C : O(1)\n int n = nums.size();\n sort(nums.begin(),nums.end());\n\n if (n<=4) {\n return 0;\n }\n\n int ... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 0 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n if (nums.size() < 4) \n {\n return 0;\n }\n\n int n = nums.size();\n \n sort(nums.begin(),nums.end());\n int result = std::min({\n nums[n - 4] - nums[0], \n ... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 1 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n int n = nums.size();\n if (n <= 4)\n return 0;\n\n sort(nums.begin(), nums.end());\n\n // 計算四種情況的最小差值\n int minDiff = nums[n - 1] - nums[3]; // 改變前三個最小值\n minDiff = min(minDiff, nums... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 1 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n int n = nums.size();\n sort(nums.begin(),nums.end());\n\n if (n<=4) {\n return 0;\n }\n\n int res = INT_MAX;\n res = min(res,nums[n-4]-nums[0]);\n res = min(res,nums[n-3]-nums... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n if(nums.size()<=4) return 0;\n sort(nums.begin(),nums.end());\n int j = nums.size()-1;\n int i = 3;\n int mini = INT_MAX;\n while(i!=-1){\n mini = min(mini,nums[j]-nums[i]);\n ... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n int n = nums.size();\n if(n <= 4){\n return 0;\n }\n sort(nums.begin(),nums.end());\n int h = n-1,l = 0;\n int mins = INT_MAX;\n for(int i = 0;i < 4;i++){\n mins = ... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "#pragma GCC optimize(\"Ofast\",\"inline\",\"fast-math\",\"unroll-loops\",\"no-stack-protector\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native\",\"f16c\")\n\nconst auto init = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(n... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n vector<int> min_four(4, INT_MAX);\n vector<int> max_four(4, INT_MIN);\n int ans = INT_MAX;\n if(nums.size() <= 4)\n return 0;\n for(int i = 0; i < nums.size(); i++) {\n if(i < 4)... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n vector<int> min_four(4, INT_MAX);\n vector<int> max_four(4, INT_MIN);\n int ans = INT_MAX;\n if(nums.size() <= 4)\n return 0;\n for(int i = 0; i < nums.size(); i++) {\n if(i < 4)... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n if(nums.size() <= 4) return 0;\n sort(nums.begin(), nums.end(), greater<int>());\n int n = nums.size() - 1;\n vector<int> tmp(nums);\n int poss1, poss2, poss3, poss4;\n nums[0] = nums[1] = ... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n int n = nums.size();\n if(n<=4) return 0;\n\n sort(nums.begin(),nums.end());\n vector<int> diff(n-1);\n for(int i =1;i<n;i++){\n diff[i-1] = nums[i]-nums[i-1];\n }\n int size ... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> mem;\n vector<int> nums;\n int minDifference(vector<int>& nums) {\n if(nums.size() <= 4) return 0;\n sort(nums.begin(), nums.end());\n this->nums = nums;\n mem.resize(4, vector<int>(4, -1));\n return dp(3,3);\n }... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> mem;\n vector<int> nums;\n int minDifference(vector<int>& nums) {\n if(nums.size() <= 4) return 0;\n sort(nums.begin(), nums.end());\n this->nums = nums;\n mem.resize(4, vector<int>(4, -1));\n return dp(3,3);\n }... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n int n=nums.size();\n if(n<=4){\n return 0;\n }\n partial_sort(begin(nums),begin(nums)+4,end(nums));\n nth_element(begin(nums)+4,begin(nums)+(n-4),end(nums));\n sort(begin(nums)+(n-4)... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n if(nums.size() <= 4) {\n return 0;\n }\n \n // sort the [0...4)\n partial_sort(nums.begin(), nums.begin()+4, nums.end());\n \n // sort the [nums.size()-4 ... nums.size()-1]\n ... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n int n=nums.size();\n if(nums.size()<=4){\n return 0;\n }\n priority_queue<int,vector<int>,greater<int>> minheap;\n priority_queue<int> maxheap;\n for(int i=0;i<n;i++){\n ... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n if(nums.size() <= 4) return 0;\n priority_queue<int> small;\n priority_queue<int, vector<int>, greater<int>> big;\n for(int x : nums){\n if(small.size() > 3){\n if(x < small.top()){\... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n if(nums.size() <= 4) return 0;\n std::partial_sort(nums.begin(), nums.begin()+4, nums.end());\n // for(const auto i : nums) std::cout << i << \", \";\n // std::cout << endl;\n std::array<int, 4> los;\... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) { \n int n=nums.size();\n if(n<=4){\n return 0;\n }\n int ans=INT_MAX;\n partial_sort(nums.begin(), nums.begin()+4, nums.end());\n partial_sort(nums.rbegin(), nums.rbegin()+4, num... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) { \n int n=nums.size();\n if(n<=4){\n return 0;\n }\n int ans=INT_MAX;\n partial_sort(nums.begin(), nums.begin()+4, nums.end());\n partial_sort(nums.rbegin(), nums.rbegin()+4, num... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n if (nums.size() <= 4) {\n return 0;\n }\n\n priority_queue<int> largest(nums.begin(), nums.end());\n priority_queue<int, vector<int>, greater<int>> smallest(nums.begin(), nums.end());\n \n ... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n if(nums.size()<=4)\n return 0;\n int n=nums.size();\n sort(begin(nums),end(nums));\n int first=nums[n-4]-nums[0];\n int second=nums[n-1]-nums[3];\n int third=nums[n-2]-nums[2];\n ... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) {\n if(nums.size() <= 4) return 0;\n sort(nums.begin(), nums.end());\n int n = nums.size();\n return min({nums[n - 4] - nums[0], nums[n - 1] - nums[3], nums[n - 3] - nums[1], nums[n - 2] - nums[2]});\n }\n}... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n int n=nums.size();\n if(n<=4)\n return 0;\n sort(nums.begin(),nums.end());\n return min({nums[n - 1] - nums[3], nums[n - 2] - nums[2], nums[n - 3] - nums[1], nums[n - 4] - nums[0]});\n\n\n\n \n }\n};",
... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n if(nums.size()<=4) return 0;\n \n sort(nums.begin(),nums.end());\n\n // we use a sliding window to \"remove/change top3 or bot3\"\n int mini=nums.front();\n int maxi=nums.back();\n\n std... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n int n=nums.size();\n if(n<=4)\n return 0;\n sort(nums.begin(),nums.end());\n return min({nums[n - 1] - nums[3], nums[n - 2] - nums[2], nums[n - 3] - nums[1], nums[n - 4] - nums[0]});\n\n\n\n \n }\n};",
... |
1,616 | <p>You are given an integer array <code>nums</code>.</p>
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</stron... | 2 | {
"code": "class Solution {\npublic:\n int minDifference(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n if(nums.size()<=4) return 0;\n int n=nums.size();\n int ans=INT_MAX;\n for(int i=0;i<4;i++){\n ans=min(ans, nums[n+i-4]-nums[i]);\n }\n retur... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 0 | {
"code": "class Solution {\npublic:\n bool winnerSquareGame(int n) {\n bool dp[n+1];\n\n memset(dp,false ,sizeof(dp));\n\n for(int i = 1; i <= n; i++){\n for(int j = 1 ; j*j <= i ; j++){\n if(!dp[i - j*j]){\n dp[i] = true;\n brea... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 0 | {
"code": "class Solution {\npublic:\n bool winnerSquareGame(int n) {\n bool dp[n+1];\n dp[0] = false, dp[1] = true;\n\n for(int stones = 2; stones <= n; stones++){\n bool win = false;\n for(int i = 1; i*i <= stones; i++){\n if(dp[stones - (i*i)] == false){... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 0 | {
"code": "class Solution {\npublic:\n bool winnerSquareGame(int n) {\n vector<bool> dp(n+1, false);\n for(int i=1;i<=n;i++){\n for(int j = 1; j*j <= i; j++){\n if(dp[i- j*j] == false){\n dp[i] = true;\n break;\n }\n ... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 0 | {
"code": "class Solution {\npublic:\n bool winnerSquareGame(int n) {\n vector<int> a;\n for (int i = 1; i * i <= n; i ++) a.push_back(i*i);\n int f[100001] = {0, 1};\n int m = a.size();\n for (int i = 2; i <= n; i ++)\n {\n int win = 0;\n for (int j ... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 1 | {
"code": "class Solution {\npublic:\n bool winnerSquareGame(int n)\n {\n // Cant think of top down\n // Bottom Up \n\n vector<bool> dp(n+1,false);\n\n dp[1]=true;\n dp[2]=false;\n\n vector<int> square;\n for(int i=1;i<=400;i++)\n {\n square.push_back(i*i)... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 1 | {
"code": "class Solution {\npublic:\n bool winnerSquareGame(int n) {\n \n vector<bool> dp(100001,0);\n //true means alice wins \n //false means bob wins\n dp[0] = false;\n dp[1] = true;\n dp[2] = false;\n dp[3] = true;\n dp[4] = true;\n\n bool flag = true;//alice turn\n\n for(... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 1 | {
"code": "using namespace std;\ntypedef uint64_t ll;\nclass Solution {\n\tconst vector<int64_t> ref ={\n\t\t-2706003,\n\t\t-1074790533,-2367755,-4327441,-295977,-554190915,\n\t\t-4257,-32769,-661,-8654849,-20973569,\n\t\t-524293,-17039363,-675414017,2078277631,-537133057,\n\t\t-1,-8454209,-671088641,-1,2080374783,\n... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 1 | {
"code": "class Solution {\npublic:\n bool winnerSquareGame(int n) {\n vector<bool> v(100001);\n vector<int> sq;\n sq.push_back(1);\n v[1] = true;\n v[2] = false;\n v[3] = true;\n for(int i = 4 ; i<=n ; i++){\n int x = sqrt(i);\n if(i == (x*x)... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 1 | {
"code": "class Solution {\npublic:\n bool winnerSquareGame(int n) {\n vector<int> arr(n + 1, 0);\n for(int i = 0; i < n; i++){\n if(arr[i] == 1)\n continue;\n\n for(int j = 1; j <= sqrt(n - i); j++)\n arr[i + pow(j, 2)] = 1;\n }\n\n ... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 1 | {
"code": "class Solution {\nprivate:\nbool isPerfectSqr(int i) {\n int l = 1, r = i, m;\n while(l < r) {\n m = l + (r - l) / 2;\n if (m * 1L * m >= i) r = m;\n else l = m + 1;\n }\n\n return l * 1L * l == i;\n}\n\nint getAns(int n) \n{ \n int* dp = new int[n + 1]; \n dp[0] = 0;... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 1 | {
"code": "class Solution {\npublic:\n vector<int>sq;\n void makesqrt(int n){\n for(int i = 1; i<=sqrt(n); i++){\n sq.push_back(i * i);\n }\n }\n bool winnerSquareGame(int n) {\n makesqrt(n);\n // for(auto it : sq)cout<<it<<\" \";\n // cout<<endl;\... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 1 | {
"code": "// class Solution {\n// public:\n// vector<int> squares;\n \n// void init() {\n// for(int i=1;;i++){\n// int sq=i*i;\n// if(sq>1e5) break;\n// squares.push_back(sq);\n// }\n// }\n \n// int dp[100000][2];\n \n// int solve(int n... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 1 | {
"code": "class Solution {\npublic:\n bool winnerSquareGame(int n) {\n vector<int> dp(n+1);\n vector<int> sq;\n for(int i=1;i<1000;i++) sq.push_back(i*i);\n dp[0] = 0;\n dp[1] = 1;\n for(int i=2;i<=n;i++){\n for(int j=0;i-sq[j]>=0;j++){\n if(dp[i... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 1 | {
"code": "class Solution {\npublic:\n bool solve(int n){\n if(n == 0)return false;\n for(int i = 1;i*i<=n; i++){\n if(!solve(n-i*i))return true;\n }\n return false;\n }\n bool solveTD(int n, vector<int>&dp){\n if(n == 0)return false;\n if(dp[n] != -1)retu... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 1 | {
"code": "class Solution {\npublic:\n bool solve(int n,int flag,vector<vector<int>> &dp){\n if(n == 0){\n if(flag == true){\n return false;\n }\n return true;\n }\n if(dp[flag][n] != -1) return dp[flag][n];\n \n bool ans = false; \... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 1 | {
"code": "class Solution {\npublic:\n int t[100001];\n int rec(int n){\n if(n<=0)return 0;\n if(t[n]!=-1)return t[n];\n for(int i=1;i*i<=n;i++){\n if(rec(n-i*i)==0)return t[n]=1;\n }\n return t[n]=0;\n \n }\n bool winnerSquareGame(int n) {\n me... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 1 | {
"code": "class Solution {\npublic:\n int dp[100005];\n int solve(int value){\n if(value == 0){\n return 0;\n }\n if(dp[value] != -1){\n return dp[value];\n }\n int ans = 0;\n for(int i = 1; i*i<=value; ++i){\n if(solve(value-i*i) == 0)... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 1 | {
"code": "class Solution {\npublic:\n int dp[100001];\n bool f(int n){\n // cout<<n<<\" \";\n if(n==0)return false;\n if(dp[n]!=-1)return dp[n];\n bool ans=false;\n for(int i=1;i*i<=n;i++){\n ans|=(f(n-i*i)^1);\n }\n return dp[n]=ans;\n }\n bool... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 1 | {
"code": "class Solution {\npublic:\n int dp[100000];\n int dfs(int n) {\n if (n < 0)\n return 0;\n if (dp[n] != -1)\n return dp[n];\n for (int i = 1; i * i <= n; i++) {\n if (dfs(n - i * i) == 0)\n return dp[n] = true;\n }\n re... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 2 | {
"code": "class Solution {\npublic:\n int dp[100001];\n int findWinner(int n) {\n // Base Case\n if(n == 0)\n return false;\n \n if(dp[n] != -1)\n return dp[n];\n\n bool possible = false;\n for(int j = 1; j * j <= n; j++){\n bool call =... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 2 | {
"code": "class Solution {\npublic:\nint dp[100001][2];\nbool f(int n,int turn ){\n if(n==0)return turn;\n // bool ans=1;\n if(dp[n][turn]!=-1)return dp[n][turn];\n if(!turn){\n bool ans=0;\n\n for(int i=1;i*i<=n;i++){\n ans|=f(n-i*i,!turn);\n }\n return dp[n][turn]=ans;\n }\n ... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 2 | {
"code": "class Solution {\npublic:\n bool f(int n){\n if(n <= 0){\n return false;\n }\n if(dp[n] != -1){\n return dp[n];\n }\n int root = sqrt(n);\n for(int i = 1;i <= root;++i){\n auto win = !f(n - i*i);\n if(win){\n ... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 2 | {
"code": "class Solution {\npublic:\n int dp[100001][2];\n int b(int n,int f){\n if(n<=0 and f==1)\n return 0;\n if(n<=0 and f==0)\n return 1;\n if(dp[n][f]!=-1)\n return dp[n][f];\n int k;\n if(f){\n int a=0;\n for(int i=1;i*i<=... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 2 | {
"code": "class Solution {\n int dp[1<<18];\npublic:\n Solution(){\n memset(dp,-1,sizeof(dp));\n }\n bool winnerSquareGame(int n) {\n if(dp[n]!=-1)return dp[n];\n if(n==0)return 0;\n int win = 0;\n for(int i=1;i*i<=n;i++){\n win = win|(!winnerSquareGame(n-i*i... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 2 | {
"code": "class Solution {\npublic:\n bool dp[100005];\n bool winnerSquareGame(int n) {\n if(n == 0)\n return false;\n if(dp[n] != NULL)\n return dp[n];\n bool isWinner = false;\n // iter through square numb <= n\n for(int i = 1;i * i <= n;i++){\n ... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 2 | {
"code": "class Solution {\npublic:\n bool dp[100005];\n bool winnerSquareGame(int n) {\n if(n == 0)\n return false;\n if(dp[n] != NULL)\n return dp[n];\n bool isWinner = false;\n // iter through square numb <= n\n for(int i = 1;i * i <= n;i++){\n ... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 2 | {
"code": "class Solution\n{\npublic:\n bool winnerSquareGame(int n)\n {\n cache.resize(std::max(n + 1, 4), kUnknown);\n cache[0] = kLose;\n cache[1] = kWin;\n cache[2] = kLose;\n cache[3] = kWin;\n Stat s = dfs(n);\n // for (int i = 0; i <= n; ++i)\n // {... |
1,617 | <p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>Initially, there are <code>n</code> stones in a pile. On each player's turn, that player makes a <em>move</em> consisting of removing <strong>any</strong> non-zero <strong>square number</strong> of stones in the pile.</p>
<p>Also, if a ... | 2 | {
"code": "class Solution\n{\npublic:\n bool winnerSquareGame(int n)\n {\n cache.resize(std::max(n + 1, 4), kUnknown);\n cache[0] = kLose;\n cache[1] = kWin;\n cache[2] = kLose;\n return dfs(n) == kWin;\n }\n\nprivate:\n enum Stat : int\n {\n kUnknown = 0,\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.