id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n vector<bool> used;\n int operationNum = 0;\n int length = nums.size();\n for (int i = 0; i < length; i++){\n used.push_back(false);\n }\n sort(nums.begin(), nums.end());\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\n const int fastio = [](){ios::sync_with_stdio(false); cin.tie(nullptr); return 0;}();\npublic:\n int maxOperations(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end());\n\n int left = 0, right = nums.size() - 1;\n int count = 0;\n while (left < ri...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "auto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\nclass Solution {\npublic:\n int maxOperations(vector<int>& nums, int k)const noexcept {\n sort(nums.begin(),nums.end());\n in...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n std::ios_base::sync_with_stdio(false);\n\t std::cin.tie(nullptr); \n sort(nums.begin(), nums.end());\n int i=0, j = nums.size()-1, ans=0;\n\n while(i<j){\n auto sum = nums[i]+nums...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n ios_base::sync_with_stdio(false); \n cin.tie(NULL); \n cout.tie(NULL);\n sort(nums.begin(), nums.end());\n int count = 0;\n int left = 0, right = nums.size()-1;\n while(right>left...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n ios_base::sync_with_stdio(false); \n cin.tie(NULL); \n cout.tie(NULL);\n sort(nums.begin(), nums.end());\n int count = 0;\n int left = 0, right = nums.size()-1;\n while(right>left...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n int count=0;\n auto radixSort = [](std::vector<int>& arr) {\n int max_num = *std::max_element(arr.begin(), arr.end());\n int exp = 1;\n std::vector<int> output(arr.size());\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n int count=0;\n auto radixSort = [](std::vector<int>& arr) {\n int max_num = *std::max_element(arr.begin(), arr.end());\n int exp = 1;\n std::vector<int> output(arr.size());\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n int count=0;\n auto radixSort = [](vector<int>& arr) {\n int max_num = *max_element(arr.begin(), arr.end());\n int exp = 1;\n vector<int> output(arr.size());\n \n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n [[nodiscard]]\n auto maxOperations( vector<int> nums, const int k) const\n -> int\n {\n if (nums.size() < 2) return 0;\n\n int max { 0 };\n\n std::ranges::sort(nums);\n int left { 0 };\n int right { static_cast<int>(nums.size() - 1)...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end());\n vector<int> final = nums;\n int left = 0; int right = nums.size()-1;\n int temp = 0;\n while(left < right){\n if(final[left] + final[right] == k){\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n int left=0,right=nums.size()-1;\n vector<int> index(nums.size(),0);\n int count=0;\n sort(nums.begin(),nums.end());\n while(left<right){\n int sum=nums[left]+nums[right];\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end());\n int n = nums.size();\n\n vector<pair<int,int>>vec;\n\n int cnt = 1;\n int ele = nums[0];\n\n for(int i=1; i<n; i++){\n if(nums[i]==ele) cnt++...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n unordered_map<int,int>m;\n int count=0;\n for(int ele:nums){\n if(ele<=k){\n m[ele]++;\n }\n }\n for(auto ele:m){\n int n=k-ele.first;\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n // 1. remove num > k\n // 2. build num -> count hash table.\n // 3. iterate the hash table to count pairs.\n\n unordered_map<int, int> m; // num -> count\n int operations = 0;\n\n for (a...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n // 1. remove num > k\n // 2. build num -> count hash table.\n // 3. iterate the hash table to count pairs.\n\n unordered_map<int, int> m; // num -> count\n int operations = 0;\n\n for (a...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n if (nums.size() < 2) return 0;\n unordered_map<int, int> occur;\n for (int num : nums) {\n if (num >= k) continue;\n if (occur.contains(num)) {\n occur[num] ++;\n } else {\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n \n unordered_map<int, int> count; // num, number of occurences\n int opp_count = 0;\n\n for (int& x : nums){\n if (x > k) continue;\n count[x]++;\n }\n\n for (int&...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n unordered_map<int,int> hash_table;\n int size = nums.size();\n int count = 0;\n \n for(int i= 0;i<size;i++)\n {\n if(nums[i]< k)\n {\n if(hash_table[...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n unordered_map<int,int> hash_table;\n int size = nums.size();\n int count = 0;\n \n for(int i= 0;i<size;i++)\n {\n if(nums[i]< k)\n {\n if(hash_table[...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int K) {\n map<int, int> m;\n for (int &v: nums) {\n if (v < K) ++m[v];\n }\n\n int res = 0, hk = K / 2, ot;\n for(auto &[k, v]: m) {\n if (k > hk) break;\n ot = K - k;\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n \n std::sort(nums.begin(), nums.end());\n\n map<int, int> found;\n int count(0);\n\n for (int i = 0; i < nums.size() && nums[i] < k; ++i) {\n int other = k-nums[i];\n if (...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n Solution(){\n ios_base::sync_with_stdio(false);\n cin.tie(NULL); cout.tie(NULL);\n }\n int maxOperations(vector<int>& nums, int k) {\n unordered_map<int, int> mp;\n for (auto it : nums) if (it < k) mp[it]++;\n\n int cnt = 0;\n i...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n Solution(){\n ios_base::sync_with_stdio(false);\n cin.tie(NULL); cout.tie(NULL);\n }\n int maxOperations(vector<int>& nums, int k) {\n unordered_map<int, int> mp;\n for (auto it : nums) if (it < k) mp[it]++;\n\n int cnt = 0;\n i...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n unordered_map<int,int> diffs;\n int result=0;\n for (int i=0;i<nums.size();i++) {\n if(diffs.find(nums[i])!=diffs.end()) {\n result++;\n if (diffs[nums[i]]>1) {\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(std::vector<int> &nums, int k)\n {\n std::vector<int> selected_nums;\n int min = INT_MAX;\n int max = 0;\n for (const int num : nums)\n {\n if (num < k)\n selected_nums.push_back(num);\n }\n std::sort(selected_nums.begin(), s...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n vector<int> v;\n for(int i : nums) {\n if(i < k) v.push_back(i);\n }\n sort(v.begin(), v.end());\n \n int left = 0, right = v.size() - 1;\n int ans = 0;\n \n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n if (nums.size() == 1) return 0;\n int ops = 0;\n int val = 0;\n unordered_map<int, int> m(nums.size()/2);\n for (int i = 0; i < nums.size(); i++) {\n if (nums[i] >= k) continue;\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n ios_base::sync_with_stdio(false);\n\n\n int len = nums.size();\n if(len==1)return 0;\n long long int count=0;\n unordered_map<long long int,long long int> hash;\n\n for(int i=0;i<len;i++...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "static const auto speedup = []() {\nstd::ios::sync_with_stdio(false); std::cin.tie(nullptr); return 0;\n}();\n\nclass Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n unordered_map<int,int> frequency;\n for (int num : nums){\n if (num < k){\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n\n int c=0;\n vector<int>v;\n int target=k;\n for(int i=0;i<nums.size();i++)\n {\n v.push_back(nums[i]);\n\n }\n \n sort(v.begin(),v.end());\n int p1=0,p2=...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n \n unordered_map<int, int> count; // num, number of occurences\n count.reserve(nums.size());\n int opp_count = 0;\n\n for (int& x : nums){\n if (x > k) continue;\n count[...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n \n unordered_map<int, int> count; // num, number of occurences\n count.reserve(nums.size());\n int opp_count = 0;\n\n for (int& x : nums){\n if (x > k) continue;\n count[...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n \n unordered_map<int, int> count; // num, number of occurences\n count.reserve(nums.size());\n int opp_count = 0;\n\n for (int& x : nums){\n if (x > k) continue;\n count[...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n int n = nums.size();\n map<int,int>mp;\n int ans = 0;\n for(int i=0;i<n;i++){\n int rem = k - nums[i];\n if(mp.find(rem)!=mp.end() && mp[rem]>0){\n cout<<i<<endl;\...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n map<int, int> M;\n int cnt = 0;\n for (int i = 0; i < nums.size(); i++) {\n int t = k - nums[i];\n if (M.find(t) != M.end() && M[t]) {\n M[t]--;\n cnt++;\n...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n map<int,int>m;\n int count=0;\n for(int i=0;i<nums.size();i++)\n {\n if(m.find(k-nums[i])!=m.end() && m[k-nums[i]]>0)\n {\n m[k-nums[i]]--;\n count+...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n \n map<int, int> m;\n \n // Store the final result\n int result = 0;\n \n // Iterate over the array nums[]\n for(auto i : nums)\n {\n \n // Decrement its frequency\n // in m ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n map<int, int> mp;\n int n= nums.size();\n int res=0;\n for (int i=0;i<n;i++){\n if (mp.find(nums[i])==mp.end() || mp[nums[i]]==0){\n if (mp.find(k-nums[i])==mp.end()){\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n unordered_map<int,int> map;\n int count = 0;\n for(int i=0;i<nums.size();i++){\n if(map.find(nums[i]) != map.end()){\n count++;\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n unordered_map<int,int> mp;\n int op = 0;\n for(int i=0;i<nums.size();i++){\n // if(nums[i] >= k)\n // break;\n if(mp.find(k - nums[i]) !=...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end());\n return solve(0, nums.size()-1, nums, k);\n }\n int solve(int i, int j, vector<int>& nums, int k){\n if(i >= j) return 0;\n \n int take = 0, reject = 0;\...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n ios_base::sync_with_stdio(false);\n map<int,int> mp;\n int ans = 0;\n for(int i =0; i< nums.size(); i++){\n if(mp.find(k-nums[i]) != mp.end() and mp[k-nums[i]] > 0){\n ans ++...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n int op = 0;\n unordered_map<int, pair<int, int>> hash;\n\n for(int i=0 ; i<nums.size() ; i++) {\n int diff = k - nums[i];\n if(hash.find(diff) != hash.end() and hash[diff].first != i an...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\n public:\n int maxOperations(vector<int>& nums, int k) {\n int ans = 0;\n unordered_map<int, int> count;\n\n for (const int num : nums)\n ++count[num];\n\n for (const auto& [num, freq] : count)\n if (const auto it = count.find(k - num); it != count.end())\n a...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n unordered_map<int, int> umap;\n int ans=0;\n\n for(int i=0;i<nums.size();i++){\n if(umap.find(nums[i])==umap.end()){\n umap[nums[i]]=0;\n }\n umap[nums[i]]++;\n }\n\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\n public:\n int maxOperations(vector<int>& nums, int k) {\n int ans = 0;\n unordered_map<int, int> count;\n\n for (const int num : nums)\n ++count[num];\n\n for (const auto& [num, freq] : count)\n if (const auto it = count.find(k - num); it != count.end())\n a...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n unordered_map<int,int>store;\n for(auto c:nums)\n store[c]++;\n\n int count=0;\n for(auto c:nums)\n {\n if(store[c]<=0)\n continue;\n store[c]--;\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\n public:\n int maxOperations(vector<int>& nums, int k) {\n int ans = 0;\n unordered_map<int, int> count;\n\n for (const int num : nums)\n ++count[num];\n\n for (const auto& [num, freq] : count)\n if (const auto it = count.find(k - num); it != count.end())\n a...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n int n=nums.size();\n int c=0;\n unordered_map<int,int> mp;\n int sum;\n for(int i=0;i<n;i++){\n sum = k-nums[i];\n if(mp.find(sum)!=mp.end()){\n // Found a ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
2
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n unordered_map <int, int> hash; int count{0};\n for (int & i : nums){\n int comp = k - i;\n unordered_map <int, int> :: iterator itr = hash.find(comp);\n if (itr != hash.end()){\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n unordered_map<int, int> cnt;\n int ans = 0;\n for (const int& num: nums) {\n int comp = k - num;\n if (!cnt.count(comp)) ++cnt[num];\n else {\n ++ans;\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n map<int, int> counts;\n for (const auto& n : nums) {\n ++counts[n];\n }\n\n int res = 0;\n for (auto& val : counts) {\n if ((val.first > k) || (val.second <= 0)) {\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\nSolution()\n {\n ios_base::sync_with_stdio(false); \n cin.tie(NULL); \n cout.tie(NULL);\n }\n int maxOperations(vector<int>& nums, int k) {\n unordered_map<int, int> map;\n int ans = 0;\n for (int e : nums){\n if (e > ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n int ans=0;\n unordered_multiset<int> hashSet;\n for (int i=0, n=nums.size(); i<n; i++) {\n if (nums[i]<k) {\n auto itr=hashSet.find(k-nums[i]);\n if (itr!=hashSet.end(...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n size_t count = nums.size();\n unordered_multiset<int> remainingValues;\n int numOps = 0;\n for (int i = 0; i < count; ++i) {\n if (nums[i] >= k) continue;\n\n // Figure out the v...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n typedef long long ll;\n int maxOperations(vector<int>& nums, int k) {\n unordered_map<ll,int> mp;\n int cnt=0,n=nums.size();\n\n for(auto it: nums)\n mp[it]++;\n\n for(auto it: mp)\n {\n if(mp.count(k-it.first) && mp[k-i...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n map<int, int> occur; set<int> values;\n for (int n : nums) {occur[n]++; \n if (2*n <= k) values.insert(n);}\n int op = 0;\n for (auto it = values.begin(); it != values.end(); it++)\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n int n=nums.size();\n int result=0;\n // Sorting and Two pointers\n // int i=0,j=n-1;\n // while(i<j){\n // if(k<nums[i]+nums[j]) j--;\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n int n = nums.size();\n int ans=0;\n vector<pair<int,int>>pqr;\n unordered_map<int,int>count;\n for(int i=0;i<n;i++)\n {\n if(nums[i]<k)\n{ count[nums[i]]++;\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n map <int, int> hash; int count{0};\n for (int & i : nums){\n int comp = k - i;\n map <int, int> :: iterator itr = hash.find(comp);\n if (itr != hash.end()){\n count++...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n int ans = 0;\n std::map<int, int> CountOfEles;\n for(int num: nums)\n {\n int remain = k - num;\n if(CountOfEles.contains(remain))\n {\n CountOfEles[rem...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n map<int,int>mp;\n int n=nums.size();\n int ans=0;\n for(int i=0;i<n;i++){\n if(mp.find(k-nums[i])!=mp.end()){\n mp[k-nums[i]]--;\n if(mp[k-nums[i]]==0){\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n map<int,int> freq;\n long long sum = 0;\n int ans = 0;\n for(int i=0;i<nums.size();i++){\n int req = k - nums[i];\n if(freq.count(req)) {\n ans++;\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n sort(nums.begin() , nums.end());\n int n = nums.size() , res = 0;\n unordered_set<int> vis;\n unordered_map<int , int> num_counter;\n for(int& it : nums) num_counter[it]++;\n\n for(int& ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n unordered_map<int,int>st;\n int count = 0;\n sort(nums.begin(),nums.end());\n for(auto x:nums){\n st[x]++;\n }\n for(int i = nums.size()-1;i >= 0;i--){\n int n = nu...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n \n int n = nums.size();\n\n unordered_map<int,int>mp;\n\n unordered_set<int>vis;\n\n for(int i=0;i<n;i++)\n {\n if(mp.find(nums[i])==mp.end())\n {\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n unordered_map<int,int> mp;\n unordered_map<int,bool>mp2;\n for(auto it : nums)\n mp[it]++;\n int ans = 0;\n for(const auto &it : mp)\n {\n int a = it.first;\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n unordered_map<int,int> freq;\n unordered_map<int,bool> visit;\n for(auto ele:nums){\n freq[ele]++;\n }\n sort(nums.begin(),nums.end());\n int ans=0;\n int n=nums.size()...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n int n = nums.size();\n int res = 0;\n std::map<int, int> sp;\n vector<int> num;\n vector<int> count;\n\n for(int i:nums)\n {\n sp[i]++;\n }\n\n for(auto& ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n int len = nums.size(), ans = 0;\n unordered_map<int, int> mp;\n for (int i: nums) {\n mp[i]++;\n }\n for (int i = 0; i < len && !mp.empty(); i++) {\n if (nums[i] == (k - n...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& v, int k) {\n int n = v.size();\n map<int,int> mp;\n for(auto it:v){\n mp[it]++;\n }\n vector<int> v1;\n for(auto it:mp){\n v1.push_back(it.first);\n }\n map<int,int> ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n unordered_map<int, int>m;\n int cnt=0;\n for(auto x : nums) m[x]++;\n for(auto x:nums){\n int diff = k-x;\n if(diff==x){\n cnt += (m[diff]/2);\n m.e...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n int ans = 0;\n unordered_map<int, int> counts;\n for (auto num : nums) {\n counts[num]++;\n }\n for (int num : nums) {\n int complement = k - num;\n if (complem...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n // int n=nums.size();\n // sort(nums.begin(),nums.end());\n // int i=0,j=n-1,cnt=0;\n // while(i<j){\n // if((nums[i]+nums[j])==k) {\n // cnt++;\n // i++;\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n unordered_map<int,int> mp; \n for(int i=0;i<nums.size();i++){\n mp[nums[i]]++; \n }\n int ans=0;\n for(int i=0;i<nums.size();i++){\n if( 2*nums[i]!=k && mp[k-nums[i]]>0 &...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n std::unordered_map<int, int> m(nums.size());\n int total = 0;\n for (int num : nums) {\n if (0 != m[k-num]) {\n m[k-num]--;\n total++;\n } else {\n ...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n unordered_map<int,int> mp; \n for(int i=0;i<nums.size();i++){\n mp[nums[i]]++; \n }\n int ans=0;\n for(int i=0;i<nums.size();i++){\n if( 2*nums[i]!=k && mp[k-nums[i]]>0 &...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n map<int, int> Count;\n for (int& x : nums) {\n Count[x]++;\n }\n int ans = 0;\n for (int& x : nums) {\n if (Count[k-x] > 0 && Count[x] > 0) {\n if (k - x ==...
1,798
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>.</p> <p>In one operation, you can pick two numbers from the array whose sum equals <code>k</code> and remove them from the array.</p> <p>Return <em>the maximum number of operations you can perform on the array</em>.</p> <p>&nbsp;</p> <...
3
{ "code": "class Solution {\npublic:\n int maxOperations(vector<int>& nums, int k) {\n map<int,int>myMap;\n for(int i:nums){\n myMap[i]++;\n }\n int count =0;\n for(int i:nums){\n if(myMap[i]==0) continue;\n int j = k-i;\n if(myMap[j]>0...
1,800
<p>Given an integer <code>n</code>, return <em>the <strong>decimal value</strong> of the binary string formed by concatenating the binary representations of </em><code>1</code><em> to </em><code>n</code><em> in order, <strong>modulo </strong></em><code>10<sup>9 </sup>+ 7</code>.</p> <p>&nbsp;</p> <p><strong class="exa...
0
{ "code": "//n\n//1*4+2\n//6*4+3\nclass Solution {\npublic:\n int concatenatedBinary(int n) {\n long int res=0,hell=1e9+7,pw=1;\n for(int i=1;i<=n;i++){\n if(pw*2<=i)pw=pw*2;\n res=(res*(pw*2)+i)%hell;\n\n // cout<<res<<\" //\";\n }\n return res;\n }\...
1,800
<p>Given an integer <code>n</code>, return <em>the <strong>decimal value</strong> of the binary string formed by concatenating the binary representations of </em><code>1</code><em> to </em><code>n</code><em> in order, <strong>modulo </strong></em><code>10<sup>9 </sup>+ 7</code>.</p> <p>&nbsp;</p> <p><strong class="exa...
0
{ "code": "class Solution {\npublic:\n int concatenatedBinary(int n) {\n long ans = 0, MOD = 1e9 + 7, len = 0;\n for (int i = 1; i <= n; ++i) {\n if(__builtin_popcount(i) == 1) ++len;\n ans = ((ans << len) % MOD + i) % MOD;\n }\n return ans;\n}\n};", "memory": "7...
1,800
<p>Given an integer <code>n</code>, return <em>the <strong>decimal value</strong> of the binary string formed by concatenating the binary representations of </em><code>1</code><em> to </em><code>n</code><em> in order, <strong>modulo </strong></em><code>10<sup>9 </sup>+ 7</code>.</p> <p>&nbsp;</p> <p><strong class="exa...
0
{ "code": "class Solution {\npublic:\n int concatenatedBinary(int n) {\n int MOD = 1e9 + 7;\n long long result = 0;\n int length = 0;\n\n for (int i = 1; i <= n; i++) {\n if ((i & (i - 1)) == 0) {\n length++;\n }\n\n result = ((result << le...
1,800
<p>Given an integer <code>n</code>, return <em>the <strong>decimal value</strong> of the binary string formed by concatenating the binary representations of </em><code>1</code><em> to </em><code>n</code><em> in order, <strong>modulo </strong></em><code>10<sup>9 </sup>+ 7</code>.</p> <p>&nbsp;</p> <p><strong class="exa...
0
{ "code": "class Solution {\npublic:\n int concatenatedBinary(int n) {\n int MOD = 1e9 + 7;\n long long result = 0;\n int length = 0;\n\n for (int i = 1; i <= n; i++) {\n if ((i & (i - 1)) == 0) {\n length++;\n }\n\n result = ((result << le...
1,800
<p>Given an integer <code>n</code>, return <em>the <strong>decimal value</strong> of the binary string formed by concatenating the binary representations of </em><code>1</code><em> to </em><code>n</code><em> in order, <strong>modulo </strong></em><code>10<sup>9 </sup>+ 7</code>.</p> <p>&nbsp;</p> <p><strong class="exa...
1
{ "code": "class Solution {\npublic:\n int concatenatedBinary(int n) {\n\n int mod = 1e9+7;\n int count=0;\n long long ans=0;\n int val=1;\n while(val<=n){\n count = log2(val)+1;\n ans = ((ans<<count) + val)%mod;\n val++;\n }\n retur...
1,800
<p>Given an integer <code>n</code>, return <em>the <strong>decimal value</strong> of the binary string formed by concatenating the binary representations of </em><code>1</code><em> to </em><code>n</code><em> in order, <strong>modulo </strong></em><code>10<sup>9 </sup>+ 7</code>.</p> <p>&nbsp;</p> <p><strong class="exa...
1
{ "code": "class Solution {\n using ll = long long;\n const ll mod = (ll)1E9 + 7;\n int count_len(int x) {\n for (int i = 30; i >= 1; i -= 1) {\n if (x & (1 << i)) return i + 1;\n }\n return 1;\n }\npublic:\n int concatenatedBinary(int n) {\n int len = 0;\n ...
1,800
<p>Given an integer <code>n</code>, return <em>the <strong>decimal value</strong> of the binary string formed by concatenating the binary representations of </em><code>1</code><em> to </em><code>n</code><em> in order, <strong>modulo </strong></em><code>10<sup>9 </sup>+ 7</code>.</p> <p>&nbsp;</p> <p><strong class="exa...
2
{ "code": "class Solution {\npublic:\n int concatenatedBinary(int n) {\n const int MOD = 1e9 + 7;\n long long result = 0;\n int length = 0;\n\n for (int i = 1; i <= n; ++i) {\n int num = i;\n int bits = 0;\n \n \n while (num > 0) {\n...
1,800
<p>Given an integer <code>n</code>, return <em>the <strong>decimal value</strong> of the binary string formed by concatenating the binary representations of </em><code>1</code><em> to </em><code>n</code><em> in order, <strong>modulo </strong></em><code>10<sup>9 </sup>+ 7</code>.</p> <p>&nbsp;</p> <p><strong class="exa...
3
{ "code": "class Solution {\npublic:\n int concatenatedBinary( int n )\n {\n const int base = 1000 * 1000 * 1000 + 7;\n\n std::vector< int > binary_digits_reversed;\n\n int result = 0;\n for ( int i = 1 ; i <=n ; ++i )\n {\n binary_digits_reversed.clear();\n ...
1,800
<p>Given an integer <code>n</code>, return <em>the <strong>decimal value</strong> of the binary string formed by concatenating the binary representations of </em><code>1</code><em> to </em><code>n</code><em> in order, <strong>modulo </strong></em><code>10<sup>9 </sup>+ 7</code>.</p> <p>&nbsp;</p> <p><strong class="exa...
3
{ "code": "class Solution {\npublic:\n int concatenatedBinary( int n )\n {\n const int base = 1000 * 1000 * 1000 + 7;\n\n std::vector< int > binary_digits_reversed;\n\n int result = 0;\n for ( int i = 1 ; i <=n ; ++i )\n {\n binary_digits_reversed.clear();\n ...
1,800
<p>Given an integer <code>n</code>, return <em>the <strong>decimal value</strong> of the binary string formed by concatenating the binary representations of </em><code>1</code><em> to </em><code>n</code><em> in order, <strong>modulo </strong></em><code>10<sup>9 </sup>+ 7</code>.</p> <p>&nbsp;</p> <p><strong class="exa...
3
{ "code": "int memo[100001];\nauto init = [](){\n memo[1] = 1;\n for(int i = 2; i < 100001; i++){\n int x = log2(i);\n for(int j = x; j >= 0; j--){\n if(i & (1 << j)){\n int num = memo[i - 1];\n for(int k = j; k > -1; k--){\n num *= 2;\n ...
1,800
<p>Given an integer <code>n</code>, return <em>the <strong>decimal value</strong> of the binary string formed by concatenating the binary representations of </em><code>1</code><em> to </em><code>n</code><em> in order, <strong>modulo </strong></em><code>10<sup>9 </sup>+ 7</code>.</p> <p>&nbsp;</p> <p><strong class="exa...
3
{ "code": "int memo[100001];\nauto init = [](){\n memo[1] = 1;\n for(int i = 2; i < 100001; i++){\n for(int j = 30; j >= 0; j--){\n if(i & (1 << j)){\n int num = memo[i - 1];\n for(int k = j; k > -1; k--){\n num *= 2;\n num %=...
1,800
<p>Given an integer <code>n</code>, return <em>the <strong>decimal value</strong> of the binary string formed by concatenating the binary representations of </em><code>1</code><em> to </em><code>n</code><em> in order, <strong>modulo </strong></em><code>10<sup>9 </sup>+ 7</code>.</p> <p>&nbsp;</p> <p><strong class="exa...
3
{ "code": "class Solution {\n constexpr static const int Base = 1'000'000'007;\n static inline int pow2(int shifts) {\n static vector<int> cache{1, 2, 4, 8, 16, 32, 64, 128, 256, 512};\n while (shifts >= cache.size()) {\n cache.push_back(cache.back() * 2 % Base);\n }\n ret...
1,800
<p>Given an integer <code>n</code>, return <em>the <strong>decimal value</strong> of the binary string formed by concatenating the binary representations of </em><code>1</code><em> to </em><code>n</code><em> in order, <strong>modulo </strong></em><code>10<sup>9 </sup>+ 7</code>.</p> <p>&nbsp;</p> <p><strong class="exa...
3
{ "code": "class Solution {\npublic:\n\n long mod = 1e9 + 7;\n\n long multiply(long a,long b){\n a%= mod;b%= mod;\n return (a*b)%mod;\n }\n\n void inverseModulo(long a,long m,long *x,long *y){ //ax congruent to 1 mod m\n\n if(!a){\n *x=0;\n *y=1;\n ret...
1,800
<p>Given an integer <code>n</code>, return <em>the <strong>decimal value</strong> of the binary string formed by concatenating the binary representations of </em><code>1</code><em> to </em><code>n</code><em> in order, <strong>modulo </strong></em><code>10<sup>9 </sup>+ 7</code>.</p> <p>&nbsp;</p> <p><strong class="exa...
3
{ "code": "class Solution {\npublic:\n\n long mod = 1e9 + 7;\n\n long multiply(long a,long b){\n a%= mod;b%= mod;\n return (a*b)%mod;\n }\n\n void inverseModulo(long a,long m,long *x,long *y){ //ax congruent to 1 mod m\n\n if(!a){\n *x=0;\n *y=1;\n ret...
1,800
<p>Given an integer <code>n</code>, return <em>the <strong>decimal value</strong> of the binary string formed by concatenating the binary representations of </em><code>1</code><em> to </em><code>n</code><em> in order, <strong>modulo </strong></em><code>10<sup>9 </sup>+ 7</code>.</p> <p>&nbsp;</p> <p><strong class="exa...
3
{ "code": "class Solution {\npublic:\n int concatenatedBinary(int n) {\n int mod = 1000000007;\n int ans = 0;\n stack<int> st;\n\n for (int i = 1; i <= n; i++) {\n int j = i;\n while (j > 0) {\n st.push(j%2);\n j /= 2;\n }\n...
1,800
<p>Given an integer <code>n</code>, return <em>the <strong>decimal value</strong> of the binary string formed by concatenating the binary representations of </em><code>1</code><em> to </em><code>n</code><em> in order, <strong>modulo </strong></em><code>10<sup>9 </sup>+ 7</code>.</p> <p>&nbsp;</p> <p><strong class="exa...
3
{ "code": "static const int mod = 1e9+7;\nint count(int a){\n int ret = 0;\n while(a){\n ret++;\n a >>= 1;\n }\n return ret;\n}\nclass Solution {\npublic:\n long long f(int n){\n if(n == 1) return 1;\n int bit = count(n);\n long long ans = (f(n-1) << bit) + n;\n ...
1,800
<p>Given an integer <code>n</code>, return <em>the <strong>decimal value</strong> of the binary string formed by concatenating the binary representations of </em><code>1</code><em> to </em><code>n</code><em> in order, <strong>modulo </strong></em><code>10<sup>9 </sup>+ 7</code>.</p> <p>&nbsp;</p> <p><strong class="exa...
3
{ "code": "class Solution {\npublic:\n int concatenatedBinary(int n) {\n if (n == 1) return 1;\n auto p = concatenatedBinary(n - 1);\n int digit = log2(n) + 1;\n return ((int64_t)p * (1 << digit) + n) % ((int)1e9 + 7);\n }\n};", "memory": "10900" }
1,800
<p>Given an integer <code>n</code>, return <em>the <strong>decimal value</strong> of the binary string formed by concatenating the binary representations of </em><code>1</code><em> to </em><code>n</code><em> in order, <strong>modulo </strong></em><code>10<sup>9 </sup>+ 7</code>.</p> <p>&nbsp;</p> <p><strong class="exa...
3
{ "code": "class Solution {\npublic:\n static const int mod = 1e9 + 7;\n\n int concatenatedBinary(int n) {\n if (n == 1)\n return 1;\n long prev = concatenatedBinary(n - 1);\n prev = prev << ((int)floor(log2(n)) + 1);\n prev += n;\n prev %= mod;\n return prev...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\n #pragma GCC optimize(\"Ofast\", \"inline\", \"unroll-loops\")\n#include <limits>\n\nauto init = []() {\n std::ios_base::sync_with_stdio(...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\n #pragma GCC optimize(\"Ofast\", \"inline\", \"unroll-loops\")\n#include <limits>\n\nauto init = []() {\n std::ios_base::sync_with_stdio(...