id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int i=0;\n vector<int> v=nums;\n sort(v.begin(),v.end());\n while(i!=(v.size()-1)){\n if(v[i]==v[i+1]) return v[i];\n i++;\n }\n return -1;\n }\n};", "memory": "51240...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n = nums.size();\n int f[int(1e6)] = {0};\n for(int i=0; i<n; i++){\n f[nums[i]]++;\n if(f[nums[i]]==2)return nums[i];\n }\n return -1;\n }\n};", "memory": "52361" }
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int arr[1000001] ={0};\n int value;\n for(int i=0;i<=nums.size();i++ ){\n arr[nums[i]] = arr[nums[i]] +1; \n if (arr[nums[i]] == 2) { value = nums[i]; break;}\n }\n return value;...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int arr[1000000] = {0};\n for(int i = 0;i < nums.size();i++){\n if(arr[nums[i]] != 0) return nums[i];\n arr[nums[i]]++;\n }\n return -1;\n }\n};", "memory": "54604" }
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n=nums.size();\n int hash[1000000]={0};\n for(int i=0;i<n;i++)\n {\n hash[nums[i]]++;\n if(hash[nums[i]]==2)\n {\n return nums[i];\n\n }\n } \n ...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n=nums.size();\n int a[1000000]={0};\n for(int i=0;i<nums.size();i++)\n { \n a[nums[i]]++;\n if(a[nums[i]]>1)\n return nums[i];\n }\n return nums[0];\n ...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n// int findDuplicate(vector<int>& nums) {\n// sort(nums.begin(),nums.end());\n// for(int i=0;i<nums.size()-1;i++){\n// if(nums[i]==nums[i+1])\n// return nums[i];\n// }\n// return -1; }\n// };\n int findDuplicate(vector<int>& ...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int max_element = INT_MIN;\n for(int i=0; i<nums.size() ; i++)\n max_element = max(max_element+1,nums[i]);\n\n vector<int>hash(max_element, 0);\n int ans=-1;\n for(auto num : nums)\n ...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int m = nums.size();\n vector<int> count(m, 0);\n vector<int> cumulativeCount(m, 0);\n\n for(auto num: nums){\n count[num]++;\n }\n cumulativeCount[1] = count[1];\n for(int i=...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n\n int n= nums.size();\n\n vector<int> arr1(n,0);\n \n arr1.resize(n+1);\n for(int i=0;i<nums.size();i++){\n if(arr1[nums[i]]==0){\n arr1[nums[i]]+=1;\n }\n ...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n=nums.size();\n int mx=10000009;\n int dummy[mx];\n for(int i=0;i<n;i++){\n dummy[i]=0;\n }\n int ans=0;\n for(int i=0;i<n;i++){\n if(dummy[nums[i]]==0){\n ...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n= nums.size();\n vector<int> arr1(n,0);\n arr1.resize(n+1);\n for(int i=0;i<nums.size();i++){\n if(arr1[nums[i]]==0){\n arr1[nums[i]]+=1;\n }\n else{\n ...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n\n int n= nums.size();\n\n vector<int> arr1(n,0);\n\n arr1.resize(n+1);\n\n for(int i=0;i<nums.size();i++){\n\n if(arr1[nums[i]]==0){\n\n arr1[nums[i]]+=1;\n\n }\n ...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n= nums.size();\n vector<int> arr1(n,0);\n arr1.resize(n+1);\n for(int i=0;i<nums.size();i++){\n if(arr1[nums[i]]==0){\n arr1[nums[i]]+=1;\n }\n else{\n ...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n vector<int>v;\n int i,n=nums.size();\n for(i=0;i<n+1;i++){\n v.push_back(0);\n }\nn=nums.size();\nint ans;\n for(i=0;i<n;i++){\n if(v[nums[i]]==1) {ans=nums[i];break;}\n ...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n vector<int> point;\n int res = 0;\n int temp = 0;\n for(int i = 0 ; i<nums.size() ; i++)\n {\n point.push_back(0);\n }\n for(int i = 0 ; i < nums.size() ; i++)\n {\n ...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int size=nums.size();\n vector<int> count={0};\n for(int i=0;i<=size;i++)\n count.push_back(0);\n \n for(int i=0;i<size;i++){\n if(count[nums[i]]==1)\n return nums...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n // map<int,int>mp;\n // for(int i=0;i<nums.size();i++){\n // mp[nums[i]]++;\n // } \n // for(auto it:mp){\n // if(it.second>=2){\n // return it.first;\n // }\n // }return -1...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int basic_solution(vector<int>arr)\n { \n int ans=0;\n for(int i=0;i<arr.size();i++)\n {\n for(int j=i+1;j<arr.size();j++)\n if(arr[i]==arr[j])\n {\n ans=arr[i];\n break;\n }\n }\n return ans;\n };\n\n int smar...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n char *mp = new char[100002];\n memset(mp, 0, 100002);\n int i = 0;\n int idx = 0;\n\n for (; i < nums.size(); ++i) {\n if (mp[nums[i]]) {\n break;\n }\n\n ...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n = nums.size();\n long long int arr[1000000] = {0}; // Auxiliary array to track occurrences\n \n for(int i = 0; i < n; i++) {\n if(arr[nums[i]] == 0) {\n arr[nums[i]] = 1; \n...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "#include <iostream>\n#include <vector>\n#include <cstdlib> // For malloc and free\n\nclass Solution {\npublic:\n // Linked List Node\n struct node {\n // key and value are both integers\n int key;\n int value;\n struct node* next;\n };\n\n // Function to initialize a...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "#define opt() ios::sync_with_stdio(0);cin.tie(0)\nclass Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n opt();\n sort(nums.begin(),nums.end());\n unordered_map<int,int> map;\n for(auto i:nums){\n map[i]++;\n if(map[i]==2){\n ...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n=nums.size();\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n sort(nums.begin(),nums.end());\n unordered_map<int,int>mp;\n for(int i=0;i<n;i++){\n mp[nums[i]]++;\n if(mp[nums[i]]>...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n=nums.size();\n unordered_map<int,int>mp;\n sort(nums.begin(),nums.end());\n int ans=0;\n for(int i=0;i<n;i++){\n mp[nums[i]]++;\n if(mp[nums[i]]>=2){\n ans=nums[i];\n ...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "// struct TreeNode{\n// int val;\n// TreeNode* right;\n// TreeNode* left;\n// };\n\nclass Solution {\npublic:\n bool add_node(TreeNode*root , int num){ \n if(root->val>num){ ///// go left\n if(root->left==NULL){\n TreeNode* nod...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "// struct TreeNode{\n// int val;\n// TreeNode* right;\n// TreeNode* left;\n// };\n\nclass Solution {\npublic:\n bool f(TreeNode*root , int num){\n if(root->val>num){\n if(root->left==NULL){\n TreeNode* node = new TreeNode();\n node->val = num;\...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n map<int, int> mp;\n for(int x : nums){\n if(mp[x] == 1) return x;\n mp[x] = 1;\n }\n return -1;\n }\n};", "memory": "80393" }
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n ios_base::sync_with_stdio(0);\n unordered_map<int, bool> q;\n q.reserve(nums.size());\n\n for(int kys : nums){\n if(!q[kys]){\n q[kys] = 1;\n } else {\n re...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n const auto n = nums.size();\n unordered_set<int> set;\n set.reserve(n);\n for (const auto num : nums) {\n auto[_, isInserted] = set.insert(num);\n if (!isInserted) {\n re...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n = nums.size();\n unordered_map<int , int> umap(n+1);\n for(auto it:nums){\n umap[it]++;\n if(umap[it] == 2){\n return it;\n }\n }\n\n return 0;\n ...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int ans;\n unordered_map<int,int> mp(nums.size());\n for(int i =0; i < nums.size(); i++){\n if(mp[nums[i]]!=1){\n mp[nums[i]]=1;\n }\n else {\n ans = n...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n unordered_map<int,int> mpp;\n for(int i = 0; i<nums.size(); i++){\n mpp[nums[i]]++;\n if(mpp[nums[i]]>1){\n return nums[i];\n }\n }\n return -1;\n }\n};", "mem...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "#include <unordered_map>\nclass Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n std::unordered_map<int, int> mapset;\n for(int i=0;i<nums.size();i++){\n if(mapset[nums[i]]++==1)\n return nums[i];\n }\n return -1;\n }\n};", "memory...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n unordered_map<int,int> counter;\n for (int i=0;i<nums.size();i++) {\n if (counter.find(nums[i]) != counter.end()) {\n return nums[i];\n ...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n unordered_map<int, int> count;\n int ans = 0;\n for (int i : nums) {\n count[i]++;\n if (count[i] > 1) {\n ans = i;\n break;\n }\n }\n re...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& n) {\n unordered_set<int> hs;\n for(auto i:n){\n if(!(hs.find(i)!=hs.end())) hs.insert(i);\n else return i;\n }\n return -1;\n }\n};", "memory": "87120" }
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n unordered_set<int> set;\n\n for(auto num : nums) {\n if(set.find(num) == set.end()) set.insert(num);\n else return num;\n }\n\n return -1;\n }\n};", "memory": "87120" }
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n unordered_map<int, int> list;\n for(auto& n : nums)\n {\n if(list.find(n) != list.end())\n {\n return n;\n }\n else\n {\n list[n]...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n unordered_set<int> seen;\n for (int n : nums) {\n if (seen.find(n) != seen.end()) {\n return n;\n }\n seen.insert(n);\n }\n return 0;\n }\n};\n", "memory"...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n = nums.size();\n map<int,int>mp;\n int ans;\n for(int i=0;i<n;i++){\n if(mp.find(nums[i])!=mp.end()){\n ans = nums[i];\n break;\n }else mp[nums[i]]++...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n map<int, int> m;\n for (const auto it : nums) {\n m[it]++;\n if (m[it] > 1) {\n return it;\n }\n }\n return 0;\n }\n};", "memory": "89363" }
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);\n vector<int> count (1e5+1,0);\n for (int i: nums){\n if (count[i]>=1) return i;\n count[i]++;\n }\n return -1;\n }\...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n vector<int>res(100001,0);\n for(int num:nums){\n res[num]++;\n if(res[num]>1)return num;\n }\n return -1;\n }\n};", "memory": "90484" }
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>v) {\n int ans;\n vector<int>freq(100005);\n\n for(int i=0; i<v.size(); i++) {\n freq[v[i]]++;\n\n if(freq[v[i]] >= 2) {\n ans = v[i];\n break;\n }\n }\n ...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n //create the hashtable\n unordered_map<int, int> mp(nums.size());\n\n for(int i=0; i<nums.size(); i++){\n mp[nums[i]]++;\n }\n\n // return the key with value > 1\n for(auto it:mp){\n...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n = nums.size();\n unordered_map<int, int> map(n);\n for(auto it: nums){\n map[it]++;\n }\n for(auto [x,y] : map){\n if(y>1){\n return x;\n }\n ...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n=nums.size();\n unordered_map<int,int> freq(n+1);\n for(int num:nums){\n freq[num]++;\n }\n sort(nums.begin(),nums.end());\n for(int i=0;i<n;i++){\n if(freq[nums[i]]>...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n unordered_map <int,int> m1;\n int l=0;\n int r=nums.size()-1;\n for(int i=0;i<nums.size();i++){\n m1[nums[l]]++;\n m1[nums[r]]++;\n if(m1[nums[l]]>1){\n return...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n \n if (nums.size() < 1) return 0;\n if (nums.size() == 2) return nums[0] == nums[1] ? nums[0] : 0;\n unordered_map<int, int> dup;\n int l = 0, r = nums.size()-1;\n\n while(l <= r) {\n ...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n unordered_set<int>order;\n int i=0,j=nums.size()-1;\n if((j+1)%2!=0) {\n order.insert(nums[j/2]);\n }\n while(i<j) {\n int it=nums[i];\n int ns=nums[j];\n i...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int checkCount(vector<int> nums,int m)\n {\n int cnt=0;\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]<=m)\n cnt++;\n }\n return cnt;\n }\n int findDuplicate(vector<int>& nums) {\n // approach 1 (cycl...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n int check(int num, vector<int> nums){\n int cnt=0;\n for (auto i:nums){\n if(i<=num){\n cnt++;\n }\n }\n return cnt;\n }\n int findDuplicate(vector<int>& nums) {\n int r= nums.size()-1;\n int...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\n bool f (int x, vector<int> a){\n int cnt = 0;\n for (int k: a) {\n if (k <= x) {\n cnt ++;\n }\n }\n return cnt > x;\n }\n int findDuplicate(vector<int>& nums) {\n \n int n = nums.size()-1;\n ...
287
<p>Given an array of integers <code>nums</code> containing&nbsp;<code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p> <p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this&nbsp;repeated&nbsp;number</em>.</p> <p>You must solve the proble...
3
{ "code": "class Solution {\npublic:\nbool func(vector<int>v,int mid){\n int k=0;\n int n=v.size();\n for(int i=0;i<n;i++){\n if(mid>=v[i]){\n k++;\n }\n }\n if(k>mid)return true;\n return false;\n}\n int findDuplicate(vector<int>& nums) {\n int lo=1;\n int ...
915
<p>Given the radius and the position of the center of a circle, implement the function <code>randPoint</code> which generates a uniform random point inside the circle.</p> <p>Implement the <code>Solution</code> class:</p> <ul> <li><code>Solution(double radius, double x_center, double y_center)</code> initializes the...
0
{ "code": "class Solution{\npublic:\n double r,x,y;\n Solution(double radius, double x_center, double y_center){\n r = radius;\n x = x_center;\n y = y_center;\n }\n vector<double> randPoint(){\n double x_r = ((double)rand()/RAND_MAX * (2*r)) + (x-r);\n double y_r = ((dou...
915
<p>Given the radius and the position of the center of a circle, implement the function <code>randPoint</code> which generates a uniform random point inside the circle.</p> <p>Implement the <code>Solution</code> class:</p> <ul> <li><code>Solution(double radius, double x_center, double y_center)</code> initializes the...
0
{ "code": "class Solution {\npublic:\n double x0 = 0;\n double y0 = 0;\n double r0 = 0;\n Solution(double radius, double x_center, double y_center) {\n x0 = x_center;\n y0 = y_center;\n r0 = radius;\n }\n \n vector<double> randPoint() {\n while (true) {\n do...
915
<p>Given the radius and the position of the center of a circle, implement the function <code>randPoint</code> which generates a uniform random point inside the circle.</p> <p>Implement the <code>Solution</code> class:</p> <ul> <li><code>Solution(double radius, double x_center, double y_center)</code> initializes the...
0
{ "code": "class Solution {\npublic:\n double x0 = 0;\n double y0 = 0;\n double r0 = 0;\n Solution(double radius, double x_center, double y_center) {\n x0 = x_center;\n y0 = y_center;\n r0 = radius;\n }\n \n vector<double> randPoint() {\n double ran = (double)rand()/RA...
915
<p>Given the radius and the position of the center of a circle, implement the function <code>randPoint</code> which generates a uniform random point inside the circle.</p> <p>Implement the <code>Solution</code> class:</p> <ul> <li><code>Solution(double radius, double x_center, double y_center)</code> initializes the...
0
{ "code": "class Solution {\npublic:\n double r;\n double x;\n double y;\n int range;\n Solution(double radius, double x_center, double y_center) {\n r = radius;\n x = x_center;\n y = y_center;\n }\n \n vector<double> randPoint() {\n double x_tmp = x - r + 2*r * (ra...
915
<p>Given the radius and the position of the center of a circle, implement the function <code>randPoint</code> which generates a uniform random point inside the circle.</p> <p>Implement the <code>Solution</code> class:</p> <ul> <li><code>Solution(double radius, double x_center, double y_center)</code> initializes the...
1
{ "code": "class Solution {\npublic:\n double RAD,XC,YC;\n Solution(double radius, double x_center, double y_center) {\n RAD=radius;\n XC=x_center;\n YC=y_center;\n }\n \n vector<double> randPoint() {\n double phi=2*M_PI*((double) rand()/RAND_MAX);\n double r=sqrt((do...
915
<p>Given the radius and the position of the center of a circle, implement the function <code>randPoint</code> which generates a uniform random point inside the circle.</p> <p>Implement the <code>Solution</code> class:</p> <ul> <li><code>Solution(double radius, double x_center, double y_center)</code> initializes the...
2
{ "code": "class Solution \n{\n double x{}, y{}, RR{};\n public:\n Solution(double r, double x, double y) : RR{r*r}, x{x}, y{y}\n { \n }\n \n vector<double> randPoint() \n {\n \t ...
915
<p>Given the radius and the position of the center of a circle, implement the function <code>randPoint</code> which generates a uniform random point inside the circle.</p> <p>Implement the <code>Solution</code> class:</p> <ul> <li><code>Solution(double radius, double x_center, double y_center)</code> initializes the...
2
{ "code": "class Solution {\nprivate:\n double centerX,centerY,rad;\npublic:\n Solution(double radius, double x_center, double y_center) {\n centerX = x_center;\n centerY = y_center;\n rad = radius;\n srand(time(NULL));\n }\n \n vector<double> randPoint() {\n vector<d...
915
<p>Given the radius and the position of the center of a circle, implement the function <code>randPoint</code> which generates a uniform random point inside the circle.</p> <p>Implement the <code>Solution</code> class:</p> <ul> <li><code>Solution(double radius, double x_center, double y_center)</code> initializes the...
3
{ "code": "class Solution final {\nprivate:\n using dbl = double;\n\n static inline piecewise_linear_distribution<dbl> radiusDistribution(\n const dbl radius\n ) noexcept {\n const auto i = {0.0, radius}, w = {0.0, 2 / radius};\n return piecewise_linear_distribution(begin(i), end(i), beg...
915
<p>Given the radius and the position of the center of a circle, implement the function <code>randPoint</code> which generates a uniform random point inside the circle.</p> <p>Implement the <code>Solution</code> class:</p> <ul> <li><code>Solution(double radius, double x_center, double y_center)</code> initializes the...
3
{ "code": "class Solution final {\nprivate:\n using dbl = double;\n\n static inline piecewise_linear_distribution<dbl> radiusDistribution(\n const dbl radius\n ) noexcept {\n const auto i = {0.0, radius}, w = {0.0, 2 / radius};\n return piecewise_linear_distribution(begin(i), end(i), beg...
915
<p>Given the radius and the position of the center of a circle, implement the function <code>randPoint</code> which generates a uniform random point inside the circle.</p> <p>Implement the <code>Solution</code> class:</p> <ul> <li><code>Solution(double radius, double x_center, double y_center)</code> initializes the...
3
{ "code": "class Solution {\n public:\n Solution(double radius, double x_center, double y_center)\n : radius(radius), x_center(x_center), y_center(y_center) {}\n\n vector<double> randPoint() {\n const double length = sqrt(distribution(generator)) * radius;\n const double degree = distribution(generator) ...
915
<p>Given the radius and the position of the center of a circle, implement the function <code>randPoint</code> which generates a uniform random point inside the circle.</p> <p>Implement the <code>Solution</code> class:</p> <ul> <li><code>Solution(double radius, double x_center, double y_center)</code> initializes the...
3
{ "code": "char c = [](){ios::sync_with_stdio(false); cin.tie(NULL); return 'c';}();\nclass Solution {\npublic:\n double radius, x_center, y_center;\n std::random_device rd;\n std::mt19937 gen;\n std::uniform_real_distribution<double> dis {0.0};\n Solution(double radius, double x_center, double y_cente...
915
<p>Given the radius and the position of the center of a circle, implement the function <code>randPoint</code> which generates a uniform random point inside the circle.</p> <p>Implement the <code>Solution</code> class:</p> <ul> <li><code>Solution(double radius, double x_center, double y_center)</code> initializes the...
3
{ "code": "class Solution {\nprivate:\n double radius, x_center, y_center; \n\npublic:\n Solution(double radius, double x_center, double y_center) {\n this->radius = radius; \n this->x_center = x_center; \n this->y_center = y_center; \n }\n\n vector<double> randPoint() {\n rand...
915
<p>Given the radius and the position of the center of a circle, implement the function <code>randPoint</code> which generates a uniform random point inside the circle.</p> <p>Implement the <code>Solution</code> class:</p> <ul> <li><code>Solution(double radius, double x_center, double y_center)</code> initializes the...
3
{ "code": "class Solution {\npublic:\n double rad,x,y;\n Solution(double radius, double x_center, double y_center) {\n rad = radius;\n x = x_center;\n y = y_center;\n }\n \n vector<double> randPoint() {\n random_device rd;\n mt19937 gen(rd());\n uniform_int_dis...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class Solution {\npublic:\n Solution() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n }\n\n double median(const std::vector<int> &nums) {\n const int N = nums.size();\n if (N % 2) return nums[N / 2];\n\n double d = (double) nums[N / 2] + nums[...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class sorted_vector {\nprivate:\n vector<int> arr;\n int k;\npublic:\n sorted_vector(int k) {\n this->k = k;\n arr = vector<int>();\n }\n \n void add(int val) {\n auto lb = lower_bound(arr.begin(), arr.end(), val);\n arr.insert(lb, val);\n }\n \n void ...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n vector<long>store;\n int ws = k;\n int i=0;\n while(k--){\n store.push_back(nums[i]);\n i++;\n }\n sort(store.begin(),store.end());\n vector...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n vector<double>ans;\n vector<long long>ab;\n\n for(int i=0;i<k;i++)\n {\n ab.insert(lower_bound(ab.begin(), ab.end(),nums[i]), nums[i]);\n }\n\n if(k%2==1) ans...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class maxHeapCom{\n public : \n bool operator()(pair<int,int>&a, pair<int,int>&b){\n if(a.first != b.first) return a.first < b.first;\n return a.second < b.second;\n }\n};\nclass minHeap{\n public : \n bool operator()(pair<int,int>& a, pair<int,int> &b){\n ...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class maxHeapCom{\n public : \n bool operator()(pair<int,int>&a, pair<int,int>&b){\n if(a.first != b.first) return a.first < b.first;\n return a.second < b.second;\n }\n};\nclass minHeap{\n public : \n bool operator()(pair<int,int>& a, pair<int,int> &b){\n ...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class maxHeapCom{\n public : \n bool operator()(pair<int,int>&a, pair<int,int>&b){\n if(a.first != b.first) return a.first < b.first;\n return a.second < b.second;\n }\n};\nclass minHeap{\n public : \n bool operator()(pair<int,int>& a, pair<int,int> &b){\n ...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class Solution {\npublic:\n\n typedef std::pair<int, int> Val;\n static bool max_heap_comp(Val a, Val b) {\n return a.second < b.second;\n };\n static bool min_heap_comp(Val a, Val b) {\n return a.second > b.second;\n };\n priority_queue<Val, vector<Val>, bool(*)(Val, Val)> ...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class maxHeap{\n public:\n bool operator()(pair<int,int>&a, pair<int,int>&b)\n {\n if(a.first!=b.first)\n {\n return a.first<b.first;\n }\n return a.second < b.second;\n }\n};\n\nclass minHeap{\n public:\n bool ope...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class maxHeapCom{\n public : \n bool operator()(pair<int,int> a,pair<int,int> b){\n if(a.first!=b.first) return a.first < b.first;\n return a.second < b.second;\n }\n};\nclass minHeap{\n public : \n bool operator()(pair<int,int> a,pair<int,int> b){\n if(a.first!=b.first)...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class Solution {\npublic:\n template<typename T> \n class Queue {\n int size_ = 0;\n T q, remove_q;\n public:\n explicit Queue(T q_, T remove_q_) : q(std::move(q_)), remove_q(std::move(remove_q_)) {}\n\n int top() {\n while (!remove_q.empty() && q.top() == re...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "\n\nclass Solution {\npublic:\n priority_queue< pair<int, int> > q_left;\n priority_queue< pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>> > q_right;\n int left = 0, right = 0;\n vector<int> where;\n\n void clean(int l){\n // cout << \"Cleaning\" << endl;\n whil...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "\n\nclass Solution {\npublic:\n priority_queue< pair<int, int> > q_left;\n priority_queue< pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>> > q_right;\n int left = 0, right = 0;\n vector<int> where;\n\n void clean(int l){\n // cout << \"Cleaning\" << endl;\n whil...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "\n\nclass Solution {\npublic:\n priority_queue< pair<int, int> > q_left;\n priority_queue< pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>> > q_right;\n int left = 0, right = 0;\n vector<int> where;\n\n void clean(int l){\n // cout << \"Cleaning\" << endl;\n whil...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "\n\nclass Solution {\npublic:\n priority_queue< pair<int, int> > q_left;\n priority_queue< pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>> > q_right;\n int left = 0, right = 0;\n vector<int> where;\n\n void clean(int l){\n // cout << \"Cleaning\" << endl;\n whil...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class Solution {\npublic:\n\n void replace(vector<int>& rsq, int mod, int i, int x) {\n i += mod;\n rsq[i] = x;\n i /= 2;\n while (i > 0) {\n rsq[i] = rsq[i + i] + rsq[i + i + 1];\n i /= 2;\n }\n }\n\n int getsum(vector<int>& rsq, int mod, i...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class Solution {\npublic:\n Solution() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n }\n\n double median(int a, int b, int k) {\n if (k % 2) return a;\n double d = static_cast<double>(a) + b;\n return d / 2.0f;\n }\n\n std::vector<double>...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class Solution {\nprivate:\n priority_queue<int> max_heap;\n priority_queue<int, vector<int>, greater<int>> min_heap;\n\n int cnt_max_heap;\n int cnt_min_heap;\n\n unordered_map<int,int> removed_elems;\n\npublic:\n Solution() {\n cnt_max_heap = 0;\n cnt_min_heap = 0;\n }\...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n unordered_map<int, int> freq;\n priority_queue<int> maxPQ;\n priority_queue<int, vector<int>, greater<int>> minPQ;\n vector<double> ans;\n\n int n = nums.size();\n int i...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n vector<double> ans;\n\n int n = nums.size();\n\n priority_queue<int> maxh;\n priority_queue<int,vector<int>,greater<int>> minh;\n\n unordered_map<int,int> m;\n\n int max...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n priority_queue<int> small;\n priority_queue<int, vector<int>, greater<int>> large;\n\n int i = 0, count = k;\n while (count--) {\n addNum(nums[i], small, large);\n ...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "\nclass Solution {\n void heap_move(priority_queue<pair<double, long>>& h1,priority_queue<pair<double, long>>& h2) {\n auto [x, i] = h1.top();\n h1.pop();\n h2.emplace(-x, i);\n }\n double get_median(priority_queue<pair<double, long>>& small, priority_queue<pair<double, long>>...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class Solution {\nprivate:\n priority_queue<int> maxHeap;\n\n priority_queue<int, vector<int>, greater<int>> minHeap;\n\n map<int, int> toRemoveNumM;\n\n int maxHeapSize = 0;\n\n int minHeapSize = 0;\n \n void insertNum(int num);\n\n void removeNum(int num);\n\n void balance();\n...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class Solution {\nprivate:\n priority_queue<int> maxHeap;\n\n priority_queue<int, vector<int>, greater<int>> minHeap;\n\n map<int, int> toRemoveNumM;\n\n int maxHeapSize = 0;\n\n int minHeapSize = 0;\n \n void insertNum(int num);\n\n void removeNum(int num);\n\n void balance();\n...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n //vector to store median \n vector<double> median;\n //map to delete the elements that are to be removed from sliding window \n unordered_map<int,int> mp;\n //to store t...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class Solution {\n public:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n vector<double> medians;\n unordered_map<int, int> outgoingNum;\n priority_queue<int> smallList;\n ...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
0
{ "code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n vector<double> medians;\n unordered_map<int, int> outgoingNum;\n priority_queue<int> smallList;\n priority_queue<int, vector<int>, greater<int>> largeList;\n\n for (int i = 0; ...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
1
{ "code": "#include <queue>\n#include <vector>\n#include <unordered_map> // already functions like a defaultdict\n\nclass Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n /*\n - two heap approach\n - assume that min is allowed to have one more than max\n ...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
1
{ "code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n vector<double> ans;\n map<int, int> hm;\n priority_queue<int> lo;\n priority_queue<int, vector<int>, greater<int>> hi;\n\n for (int i = 0; i < k; i++) {\n lo.push(nu...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
1
{ "code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n vector<double>ans;\n unordered_map<int,int>mp;//to account for late deletions\n priority_queue<double>left; //maxHeap\n priority_queue<double,vector<double>,greater<double>>right; //m...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
1
{ "code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n vector<double> result;\n result.reserve(nums.size() - k + 1);\n multiset<long int> sorted_window;\n auto iter = sorted_window.begin();\n for (size_t i = 0; i < nums.size(); ++i...
480
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p> <ul> <li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li> <li>For examples, if <code>...
1
{ "code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n int n = nums.size();\n vector<double> ans(n - k + 1);\n multiset<double> window(nums.begin(), nums.begin() + k);\n multiset<double>::iterator it = next(window.begin(), (k - 1) / 2);\n...