id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n vector<int> ans;\n vector<int> empty;\n // hshTable[value] = frequency\n int hashTable[200001] = {0};\n for(int i = 0; i < changed.size(); i++)\n hashTable[changed[i]]++;\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) { \n int n = changed.size() ; \n vector<int> ans , empty; \n\n if(n % 2 == 1) return empty ; \n\n int num[100005] ; \n memset(num, 0 , sizeof(num)) ;\n for(int x: changed) {\n...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n sort(changed.begin(), changed.end());\n vector<int> m;\n int i = 0;\n for (int n: changed) {\n if (m.size() == i) {\n m.emplace_back(n);\n } else if (m[i] ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n priority_queue<int, vector<int>, greater<int>> minH;\n sort(changed.begin(),changed.end());\n\n minH.push(changed[0]);\n vector<int> ans;\n\n for(int i=1;i<changed.size();i++){\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "\nclass Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int n = changed.size();\n if(n % 2) return {};\n int MX = *max_element(changed.begin(), changed.end());\n vector<int> count(1+MX);\n for(auto c : changed) count[c]++;\n vector<...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "/*\nApproach: normal Sort\nWe need to pair up elements in the array as explained above. Thus, the first validation we should do is, if the array size is even or not. If it's not we cannot have an answer.\nWe need to find the smallest element at each iteration. Hence, we can prepare a fred array \nusing cou...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int>findOriginalArray(vector<int>&changed) {\n int n = changed.size();\n vector<int>a,visited(n,0); \n\t\t// Sorting the array is important in this approach\n sort(changed.begin(), changed.end());\n\t\t\n int i=0,j=1;\n while((...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int left=0;\n int right=1;\n sort(changed.begin(),changed.end());\n vector<int> f;\n if(changed.size()%2==1){\n return f;\n }\n int n=changed.size();\n f...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": " \nclass Solution {\npublic:\n vector<int>findOriginalArray(vector<int>&changed) {\n int n = changed.size();\n vector<int>a,visited(n,0); \n\t\t// Sorting the array is important in this approach\n sort(changed.begin(), changed.end());\n\t\t\n int i=0,j=1;\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n sort(changed.begin(), changed.end());\n int n=changed.size();\n vector<int> z = vector<int>(n, 1);\n bool hasAns=true;\n vector<int> ans;\n int ptr=0;\n for (int i=0; i<n;...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int n = changed.size();\n sort(changed.begin(), changed.end());\n int maxi = -1;\n for(auto change: changed){\n maxi = max(change, maxi);\n }\n vector<int> freq(maxi+1...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n // It can't be doubled array, if the size is odd\n if (changed.size() % 2) {\n return {};\n }\n \n int maxNum = 0;\n // Find the max element in the array\n for ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n // It can't be doubled array, if the size is odd\n if (changed.size() % 2) {\n return {};\n }\n \n int maxNum = 0;\n // Find the max element in the array\n for ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n if (changed.size() % 2) return {};\n \n int max_num = changed[max_element(changed.begin(), changed.end()) - changed.begin()];\n vector<int> freq(2 * max_num + 1, 0);\n \n for(int...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n if (changed.size() % 2) return {};\n \n int max_num = changed[max_element(changed.begin(), changed.end()) - changed.begin()];\n vector<int> freq(2 * max_num + 1, 0);\n \n for(int...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int n = changed.size();\n if(n%2)\n return {};\n\n int N = 0;\n\n for(auto val:changed){\n N = max(N,val);\n }\n\n vector<int> ans;\n //unordered_map<int,...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\n public:\n vector<int> findOriginalArray(vector<int>& changed) {\n vector<int> ans;\n queue<int> q;\n\n ranges::sort(changed);\n\n for (const int num : changed)\n if (!q.empty() && num == q.front()) {\n q.pop();\n } else {\n q.push(num * 2);\n a...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int> &changed) {\n queue<int> q;\n vector<int> result;\n sort(changed.begin(), changed.end());\n\t\t\n for (int &i : changed) {\n if (q.front() != i) {\n result.push_back(i);\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n vector<int>ans;\n queue<int>q;\n\n ranges::sort(changed);\n\n for(const int num:changed){\n if(!q.empty() && num==q.front()){\n q.pop();\n }else{ \n q.push(num*2);\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int> &changed) {\n queue<int> q;\n vector<int> result;\n sort(changed.begin(), changed.end());\n\t\t\n for (int &i : changed) {\n if (q.front() != i) {\n result.push_back(i);\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int size = changed.size();\n if(size&1){\n return {};\n }\n sort(changed.begin(), changed.end());\n unordered_map<int, int> mp;\n auto countZero = 0;\n vector<i...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int size = changed.size();\n if(size&1){\n return {};\n }\n sort(changed.begin(), changed.end());\n unordered_map<int, int> mp;\n vector<int> res;\n for(auto n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& v) {\n int n=v.size();\n if(n%2==1) return {};\n\n vector<int> ans;\n sort(v.begin(),v.end());\n unordered_map<int,int> m;\n\n for(auto it:v){\n if(it%2==0 && m.find(it/2)!=m.end()...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& arr)\n {\n // sort the array\n // for every element after the first one\n // we don't know if it's part of the original or part of changed\n \n // if half of its value has occurred before then de...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n vector <int> res;\n sort(changed.begin() , changed.end());\n unordered_map <int , int> freq;\n for(int i = changed.size() - 1 ; i >= 0 ; i--){\n if(freq.count(changed[i] * 2)){\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& ch) {\n \n map<int,int>m;\n vector<int>ans;\n if(ch.size()%2==1) {\n return ans;\n }\n sort(ch.begin(),ch.end());\n for(int i=0;i<ch.size();i++) {\n if(!m.count(c...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int n = changed.size();\n if (n & 1) return {};\n priority_queue<int, vector<int>, greater<int>> pq;\n for(int num: changed) {\n pq.push(num);\n }\n queue<int> doubled...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n \n vector<int> ans;\n unordered_map<int,int> ump;\n int n=changed.size();\n if(n&1){\n return {};\n }\n sort(changed.begin(),changed.end());\n bool visze...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& arr) {\n int n = arr.size();\n unordered_map<int,int>mp;\n sort(arr.begin(),arr.end());\n vector<int>ans;\n for(int i = 0; i < n; i++){\n // cout << arr[i]/2<<endl;\n if( arr[i...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n if (changed.size() % 2 != 0) return {};\n \n vector<int> ans;\n unordered_map<int, int> count;\n ans.reserve(changed.size() / 2);\n \n sort(changed.begin(), changed.end())...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int n = changed.size();\n unordered_map<int, int> map;\n for(int i = 0; i < n; i++) map[changed[i]]++;\n vector<int> ret;\n ret.reserve(n/2);\n vector<int> failureRet;\n w...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n unordered_map<int,int> mp;\n int n = changed.size();\n sort(changed.begin(),changed.end());\n vector<int> result;\n for(int i=0;i<n;i++){\n int num = changed[i];\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n unordered_map<int,int> mp;\n int n = changed.size();\n if(n % 2 != 0) return {};\n sort(changed.begin(),changed.end());\n vector<int> result;\n for(int i=0;i<n;i++){\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
0
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n // Sort changed in reverse order.\n sort(changed.begin(), changed.end(), greater<int>());\n\n // The original array.\n vector<int> original;\n\n // These numbers must exist.\n mu...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
1
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int n = changed.size();\n if(n&1) return {};\n\n vector<int> res;\n unordered_map<int,int> freq;\n for(int it : changed)\n freq[it]++;\n\n sort(changed.begin(),changed.end...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
1
{ "code": "#include <vector>\n#include <set>\n#include <algorithm>\n\nclass Solution {\npublic:\n #include <vector>\n#include <unordered_map>\n#include <algorithm>\n\nstd::vector<int> findOriginalArray(std::vector<int>& d) {\n std::unordered_map<int, int> count;\n std::vector<int> ans;\n\n // Count the fr...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
2
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n vector<int> emptyVec;\n if (changed.size() % 2 == 1) return emptyVec;\n unordered_map<int, int> freq;\n for (int i = 0; i < changed.size(); i++) {\n freq[changed[i]]++;\n }\n...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
2
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& v) {\n \n int n = v.size() , count =0;\n if(n % 2) return {};\n vector<int> res;\n sort(v.begin(),v.end());\n unordered_map<int,int> m;\n for(auto x:v) m[x]++;\n for(auto x:v) {...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
2
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n\n if(changed.size()%2!=0)\n return {};\n\n vector<int>ans;\n unordered_map<int,int>mp;\n unordered_map<int,int>used;\n\n sort(changed.begin(),changed.end());\n for(int i=0;i<changed.size();i++)\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
2
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n vector<int> ans;\n int n = changed.size();\n if (n % 2 != 0) return {};\n\n map<int, int> mp;\n for (int i = 0; i < n; i++){\n mp[changed[i]]++;\n }\n\n for (au...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
2
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int n=changed.size();\n if(n%2!=0){\n return {};\n }\n sort(changed.begin(),changed.end());\n map<int,int>mp;\n vector<int>result;\n for(auto &num:changed){\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
2
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int n=changed.size();\n if(n%2==1){\n return {};\n }\n sort(changed.begin(),changed.end());\n vector<int>ans;\n map<int,int>mp;\n for(int i=0;i<n;i++){\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int n = changed.size(); \n if(n == 0 || n % 2)\n return vector<int>();\n\n map<int,int> M;\n for(int num : changed)\n M[num]++;\n\n vector<int> result;\n fo...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n sort(changed.begin(),changed.end());\n map<int,int>hash;\n vector<int>res;\n for(auto &it:changed)\n {\n if(it%2==0)\n {\n if(hash.find(it...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n map<int, int> freq;\n for (auto x : changed) {\n freq[x]++;\n }\n\n vector<int> ans;\n bool doubled = changed.size() % 2 == 0;\n for (auto& x : freq) {\n if...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n if (changed.size() % 2 != 0) return {};\n unordered_map<int, int> count;\n for (int num : changed) count[num]++;\n vector<int> keys;\n for (auto& [key, _] : count) keys.push_back(key);\...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n vector<int> ans;\n if(changed.size()%2)\n return ans;\n sort(changed.begin(), changed.end());\n bool idChanged=true;\n map<int, bool> isDeleted;\n int idx;\n for(in...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n vector<int> ans;\n if(changed.size()%2)\n return ans;\n sort(changed.begin(), changed.end());\n // bool idChanged=true;\n map<int, bool> isDeleted;\n int idx;\n for...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution\n{\npublic:\n vector<int> findOriginalArray(vector<int> &changed)\n {\n int n = changed.size();\n sort(changed.rbegin(),changed.rend());\n if(n%2==0)\n {\n map<int, int> mpp;\n vector<int> v;\n for (int i = 0; i < n; i++)\n {\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int n = changed.size();\n\n if(n%2) {\n return vector<int>();\n }\n\n vector<int> v;\n\n map<int, int> m;\n\n for(int i=0; i<n; ++i) {\n ++m[changed[i]];\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& nums) {\n int n = nums.size();\n\n if (n % 2 )\n return {};\n unordered_map<int,int>um;\n \n sort(nums.begin(), nums.end());\n \n for (int i=0; i<nums.size(); i++)\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int len = changed.size();\n if (len % 2 == 1) {\n return {};\n }\n\n sort(changed.begin(), changed.end());\n\n unordered_map<int, int> cnt;\n for (int i: changed) {\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int len = changed.size();\n if (len % 2 == 1) {\n return {};\n }\n\n sort(changed.begin(), changed.end());\n\n unordered_map<int, int> cnt;\n for (int i: changed) {\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n if(changed.size()%2==1){\n return {};\n }\n unordered_map<int,int> mp;\n vector<int> ans;\n int s = changed.size()/2;\n for(auto i:changed){\n mp[i]++;\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& a) {\n int n = a.size();\n if(n % 2 == 1) return {};\n vector<int> v;\n map<int, int> m;\n sort(a.begin(), a.end());\n for(auto x : a) if(x % 2 == 0) m[x]++;\n for(int i = 0; i < n; i+...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& v) {\n \n vector<int> ans;\n if(v.size() % 2) return ans;\n map<int,int> m;\n for(int i=0;i<v.size();i++) m[v[i]]++;\n sort(v.begin(),v.end());\n for(int i=0;i<v.size();i++){\n\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n sort(changed.rbegin(), changed.rend());\n unordered_map<int,int>mp;\n vector<int>ans;\n for(auto &i:changed){\n if(mp[2*i]>0){\n ans.push_back(i);\n mp...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int n = changed.size();\n vector<int> result;\n if (n%2!=0){\n return {};\n }\n unordered_map<int,int> freq;\n for (int i:changed){\n freq[i]++;\n }\...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\nmap<int,int> mp;\n vector<int> findOriginalArray(vector<int>& changed) {\n vector<int> v;\n sort(changed.begin(), changed.end());\n for(int i=0; i<changed.size(); i++)\n {\n if(mp[changed[i]])\n {\n mp[changed[i]...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& c) {\n int n = c.size();\n priority_queue <int, vector<int>, greater<int>> pq;\n map<int,int>m;\n for(int i=0;i<n;i++){\n pq.push(c[i]);\n m[c[i]]++;\n }\n \n vec...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int n=changed.size();\n if(n%2==1)return {};\n sort(changed.begin(),changed.end());\n map<int,int> mp,vis;\n vector<int> ans;\n for(auto it:changed)mp[it]++;\n for(auto it...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n vector<int> res;\n if(changed.size()%2==1) return res;\n unordered_map<int,int> m;\n for(auto num:changed){\n m[num]++;\n }\n set<int> s(changed.begin(),changed.end())...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n vector<int> res;\n if(changed.size()%2==1) return res;\n unordered_map<int,int> m;\n for(auto num:changed){\n m[num]++;\n }\n set<int> s(changed.begin(),changed.end())...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n vector<int> res;\n if(changed.size()%2==1) return res;\n unordered_map<int,int> m;\n for(auto num:changed){\n m[num]++;\n }\n set<int> s(changed.begin(),changed.end())...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n bool canReorderDoubled(vector<int>& arr) {\n unordered_map<int,int>hash;\n sort(arr.begin(),arr.end());\n for(int i=0;i<arr.size();i++){\n hash[arr[i]]++;\n }\n for(int i=0;i<arr.size();i++)\n {\n if(hash[arr[i...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int n = changed.size();\n if(n%2!=0) return {};\n\n sort(changed.begin(), changed.end());\n multiset<int> seen;\n vector<int> res;\n for(int i=0; i<n; i++){\n int num ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int n = changed.size();\n if(n%2!=0) return {};\n\n sort(changed.begin(), changed.end());\n multiset<int> seen;\n vector<int> res;\n for(int i=0; i<n; i++){\n int num ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n vector<int> original;\n if(changed.size()%2)return original;\n\n unordered_map<int,int> occursChanged,occursorg;\n for(auto num:changed){\n occursChanged[num]+=1;\n }\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n vector<int> original;\n if(changed.size()%2)return original;\n\n unordered_map<int,int> occursChanged,occursorg;\n for(auto num:changed){\n occursChanged[num]+=1;\n }\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& arr) {\n int n = arr.size();\n if(n % 2 == 1){\n return {};\n }\n\n sort(arr.begin(), arr.end());\n\n unordered_multiset<int> st;\n int zeros = 0;\n\n for(auto &x: arr){\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n if(changed.size()&1) return {};\n\n multiset<int> s;\n \n int countZeros = 0;\n for(auto &i: changed) {\n if(i==0) ++countZeros;\n else s.insert(i);\n }\n\n...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n ios_base::sync_with_stdio(false); cin.tie(0);\n if (changed.size()%2==1) return {};\n \n int cnt=0;\n multiset<int> ms;\n vector<int> ans;\n for (int i=0;i<changed.size();...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n ios_base::sync_with_stdio(false); cin.tie(0);\n if (changed.size()%2==1) return {};\n \n int cnt=0;\n multiset<int> ms;\n vector<int> ans;\n for (int i=0;i<changed.size();...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n ios_base::sync_with_stdio(false); cin.tie(0);\n if (changed.size()%2==1) return {};\n \n int cnt=0;\n multiset<int> ms;\n vector<int> ans;\n for (int i=0;i<changed.size();...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n ios_base::sync_with_stdio(false); cin.tie(0);\n if (changed.size()%2==1) return {};\n \n int cnt=0;\n multiset<int> ms;\n vector<int> ans;\n for (int i=0;i<changed.size();...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n ios_base::sync_with_stdio(false); cin.tie(0);\n if (changed.size()%2==1) return {};\n \n int cnt=0;\n multiset<int> ms;\n vector<int> ans;\n for (int i=0;i<changed.size();...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int n=changed.size();\n multiset<int>mt;\n vector<int>ans;\n int cnt0=0;\n for(int i=0;i<n;i++)\n {\n if(changed[i]==0)\n {\n cnt0++;\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int n = changed.size();\n if(n%2)return {};\n multiset<int>st;\n int zeroCnt = 0;\n for(int i=0;i<n;i++){\n if(changed[i]==0)\n zeroCnt++;\n else\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n const int nmax = 1e5;\n int n = changed.size();\n\n if (n % 2) return vector<int>();\n\n vector<int> cnt(nmax + 1);\n for (int i: changed) cnt[i]++;\n if (cnt[0] % 2) return vect...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n // if(changed=={1,2,1,0}) return {};\n unordered_map<int,vector<int>> mpp;\n int cnt=0;\n int n=changed.size();\n if(n&1) return {};\n sort(changed.begin(),changed.end());\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\n public:\n vector<int> findOriginalArray(vector<int>& changed)\n {\n if (changed.size() % 2 != 0)\n return {};\n\n\n vector<int> nums(100001);\n for (size_t i = 0; i < changed.size(); i++)\n nums[changed[i]]++;\n\n if (nums[0] % 2...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\n public:\n vector<int> findOriginalArray(vector<int>& changed)\n {\n if (changed.size() % 2 != 0)\n return {};\n\n\n vector<int> nums(100001);\n for (size_t i = 0; i < changed.size(); i++)\n nums[changed[i]]++;\n\n if (nums[0] % 2...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution1 {\n public:\n vector<int> findOriginalArray(vector<int>& changed) {\n sort(changed.begin(),changed.end());\n vector<int> original;\n int i,j;\n for(i=0;i<changed.size();i++){\n if(changed[i]==-1)continue;\n else{\n j=get...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n map<int, int> mp;\n vector<int> original;\n vector<int> empty;\n if (changed.size()%2 == 1)return empty;\n\n for (int i = 0; i < changed.size(); i++) {\n mp[changed[i]]++;\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "static int io_opt = []() {\n std::ios::sync_with_stdio(false);\n return 0;\n}();\n\nclass Solution {\n public:\n vector<int> findOriginalArray(vector<int>& changed) {\n if (changed.size() & 1) return vector<int>();\n sort(changed.begin(), changed.end());\n vector<int> cache(100001, 0);\n int...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n // if(changed=={1,2,1,0}) return {};\n unordered_map<int,vector<int>> mpp;\n int cnt=0;\n int n=changed.size();\n if(n&1) return {};\n sort(changed.begin(),changed.end());\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n // if(changed=={1,2,1,0}) return {};\n unordered_map<int,vector<int>> mpp;\n int cnt=0;\n int n=changed.size();\n if(n&1) return {};\n sort(changed.begin(),changed.end());\n ...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& nums) {\n int n=nums.size();\n if(n%2)return {};\n sort(nums.begin(),nums.end());\n unordered_map<int,int>mpp;\n\n for(auto it:nums){\n mpp[it]++;\n }\n //int cnt=0;\n vector<...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n if(changed.size() % 2) return {};\n sort(changed.rbegin(), changed.rend());\n vector<int> ans;\n int n = changed.size();\n unordered_multiset<int> s;\n for(auto num : changed) s....
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n int n = changed.size(), st =0;\n if(n % 2) return {};\n sort(changed.rbegin(), changed.rend());\n vector<int> ans(n/2);\n unordered_multiset<int> s;\n for(auto num : changed) s.i...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n vector<int> findOriginalArray(vector<int>& changed) {\n if (changed.size() % 2 != 0) return {};\n multiset<int> s ;\n vector<int> ans ;\n for(auto it: changed){\n s.insert(it);\n }\n\n while(! s.empty()){\n int s...
2,117
<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, retu...
3
{ "code": "class Solution {\npublic:\n // vector<int> findOriginalArray(vector<int>& changed) {\n // multiset<int> ms;\n // for(int i=0;i<changed.size();i++) ms.insert(changed[i]);\n // vector<int> ans;\n // for(auto ele : ms){\n // if(ms.find(ele*2)!=ms.end()){\n // ...
2,119
<p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p> <p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p> <ul> <li>All elements i...
0
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n const int n=nums.size();\n int ans=n;\n \n ranges::sort(nums);\n nums.erase(unique(nums.begin(),nums.end()),nums.end());\n\n for(int i=0;i<n;++i){\n const int start=nums[i];\n const int end=s...
2,119
<p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p> <p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p> <ul> <li>All elements i...
0
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n const int n = nums.size();\n int ans=n;\n\n ranges::sort(nums);\n nums.erase(unique(nums.begin(),nums.end()),nums.end());\n\n for(int i=0;i<n;++i){\n const int start = nums[i];\n const int end = s...
2,119
<p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p> <p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p> <ul> <li>All elements i...
0
{ "code": "class Solution {\n public:\n int minOperations(vector<int>& nums) {\n const int n = nums.size();\n int ans = n;\n\n ranges::sort(nums);\n nums.erase(unique(nums.begin(), nums.end()), nums.end());\n\n for (int i = 0; i < nums.size(); ++i) {\n const int start = nums[i];\n const int ...
2,119
<p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p> <p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p> <ul> <li>All elements i...
0
{ "code": "class Solution {\n public:\n int minOperations(vector<int>& nums) {\n const int n = nums.size();\n int ans = n;\n\n ranges::sort(nums);\n nums.erase(unique(nums.begin(), nums.end()), nums.end());\n\n for (int i = 0; i < nums.size(); ++i) {\n const int start = nums[i];\n const int ...
2,119
<p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p> <p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p> <ul> <li>All elements i...
0
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int m = unique(nums.begin(), nums.end()) - nums.begin();\n int n = nums.size();\n int ans = n;\n for (int i = 0; i < m; ++i) {\n int j = upper_bound(nums.b...
2,119
<p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p> <p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p> <ul> <li>All elements i...
0
{ "code": "class Solution {\npublic:\n // time/space: O(nlogn)/O(n)\n int minOperations(vector<int>& nums) {\n // get the sorted and unique integers\n int n = nums.size();\n sort(nums.begin(), nums.end());\n int k = unique(nums.begin(), nums.end()) - nums.begin();\n \n ...
2,119
<p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p> <p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p> <ul> <li>All elements i...
0
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n \n int n = nums.size();\n sort(nums.begin(), nums.end());\n int k = unique(nums.begin(), nums.end()) - nums.begin();\n //cout << k << \"\\n\";\n int result = INT_MAX;\n for (int l = 0, r...
2,119
<p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p> <p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p> <ul> <li>All elements i...
0
{ "code": "class Solution {\npublic:\n // time/space: O(nlogn)/O(n)\n int minOperations(vector<int>& nums) {\n // get the sorted and unique integers\n int n = nums.size();\n sort(nums.begin(), nums.end());\n int k = unique(nums.begin(), nums.end()) - nums.begin();\n \n ...