question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
the-k-strongest-values-in-an-array | [Java] Without PriorityQueue, it can be faster. 100%, 100%! | java-without-priorityqueue-it-can-be-fas-8na6 | \nclass Solution {\n public int[] getStrongest(int[] arr, int k) {\n Arrays.sort(arr); \n int[] result = new int [k];\n i | lincanshu | NORMAL | 2020-06-07T07:12:08.732116+00:00 | 2020-06-08T02:30:31.770696+00:00 | 128 | false | ```\nclass Solution {\n public int[] getStrongest(int[] arr, int k) {\n Arrays.sort(arr); \n int[] result = new int [k];\n int lo = 0, hi = arr.length - 1;\n int m = arr[hi / 2];\n for (int i = 0; i < k; ++ i) {\n int diff = Math.abs(arr[lo] - m) - Math.ab... | 1 | 1 | ['Java'] | 1 |
the-k-strongest-values-in-an-array | [C++] Using pairs and custom comparator | c-using-pairs-and-custom-comparator-by-s-44st | Pls upvote if you find this helpful :)\nThe basic idea is to first get the array sorted and find the median .After getting median we store the absolute differe | shubhambhatt__ | NORMAL | 2020-06-07T06:48:59.324480+00:00 | 2020-06-07T06:48:59.324529+00:00 | 128 | false | ***Pls upvote if you find this helpful :)***\nThe basic idea is to first get the array sorted and find the median .After getting median we store the absolute difference of the array values and median and the value itself in an array of pairs.And then we define our custom comparator for the purpose.\nAt last we find th... | 1 | 0 | ['C', 'C++'] | 0 |
the-k-strongest-values-in-an-array | C++ Simplest solution | Two pointer | Sorting | c-simplest-solution-two-pointer-sorting-8v58n | \nvector<int> getStrongest(vector<int>& arr, int k) {\n sort(arr.begin(), arr.end());\n int len = arr.size();\n int median = arr[(len-1)/2] | Atyant | NORMAL | 2020-06-07T06:31:05.508228+00:00 | 2020-06-07T06:49:19.887056+00:00 | 83 | false | ```\nvector<int> getStrongest(vector<int>& arr, int k) {\n sort(arr.begin(), arr.end());\n int len = arr.size();\n int median = arr[(len-1)/2];\n vector<int> ans;\n int li = 0, ri = len-1;\n while(ans.size()<k && li<=ri){\n if(abs(arr[ri]-median)>=abs(arr[li]-median)... | 1 | 0 | ['Two Pointers', 'C', 'Sorting', 'C++'] | 0 |
the-k-strongest-values-in-an-array | [Python] 3 Solutions: Sort, Heap, Two-Pointer | python-3-solutions-sort-heap-two-pointer-lzi3 | Double Sort\npython\nclass Solution:\n def getStrongest(self, arr: List[int], k: int) -> List[int]:\n arr.sort()\n m = arr[((len(arr) - 1) // 2 | ztonege | NORMAL | 2020-06-07T05:33:15.156107+00:00 | 2020-06-07T05:33:15.156141+00:00 | 37 | false | **Double Sort**\n```python\nclass Solution:\n def getStrongest(self, arr: List[int], k: int) -> List[int]:\n arr.sort()\n m = arr[((len(arr) - 1) // 2)]\n return sorted(arr, key = lambda x: (abs(x - m), x), reverse = True)[:k]\n```\n\n**Heap**\n```python\nclass Solution:\n def getStrongest(se... | 1 | 0 | [] | 0 |
the-k-strongest-values-in-an-array | huh? TLE when I originally submitted nlogk solution in contest, which now passes and beats 100% | huh-tle-when-i-originally-submitted-nlog-9ejl | I posted below O(nlogk) solution during contest and it gave me "Time Limit Exceeded". Now after looking at all the solutions here which are also nlogk, I resubm | cham_ | NORMAL | 2020-06-07T05:29:48.440918+00:00 | 2020-06-07T07:07:42.274233+00:00 | 50 | false | I posted below O(nlogk) solution during contest and it gave me "Time Limit Exceeded". Now after looking at all the solutions here which are also nlogk, I resubmitted the same code again and now it passes beating 100% submissions for memory and 50% submissions for time complexity. \n\nWhat does this even mean??\n\n\n```... | 1 | 0 | [] | 1 |
recover-the-original-array | [Python] Short solution, explained | python-short-solution-explained-by-dbabi-anke | Notice, that what we have in the end is sum array X and array X + 2k. It seems very familiar and you can use the greedy idea of 954. Array of Doubled Pairs, but | dbabichev | NORMAL | 2021-12-26T04:00:47.975306+00:00 | 2021-12-26T04:00:47.975339+00:00 | 4,281 | false | Notice, that what we have in the end is sum array `X` and array `X + 2k`. It seems very familiar and you can use the greedy idea of 954. Array of Doubled Pairs, but now pairs are not doubled but with constant difference. How to find difference? It can be one of `n-1` numbers: `a1 - a0, a2 - a0, ...`. Also we need to ma... | 100 | 4 | ['Greedy'] | 13 |
recover-the-original-array | [100%] [50ms] WITHOUT map | 100-50ms-without-map-by-lyronly-2klu | First sort the nums array, nums[0] belong to low array. \nTry every possible diff in array, and diff must be even. k = diff / 2;\nEach element in low array (v) | lyronly | NORMAL | 2021-12-26T05:21:26.089182+00:00 | 2021-12-26T07:43:20.374917+00:00 | 1,991 | false | First sort the nums array, nums[0] belong to low array. \nTry every possible diff in array, and diff must be even. k = diff / 2;\nEach element in low array (v) should have its equivalent in high arrray (v + k + k). \nMaintain a pointer for the last element in low array that haven\'t found its equalient in high array ... | 33 | 2 | ['Greedy', 'C'] | 10 |
recover-the-original-array | Try possible k | try-possible-k-by-votrubac-hz2u | The smallest element in nums must be in the lower array. If we sort the array, our k can be (nums[i] - nums[0]) / 2.\n\nFor each such k, we try to match all pai | votrubac | NORMAL | 2021-12-26T04:01:45.915125+00:00 | 2021-12-26T04:18:32.954991+00:00 | 3,864 | false | The smallest element in `nums` must be in the lower array. If we sort the array, our `k` can be `(nums[i] - nums[0]) / 2`.\n\nFor each such `k`, we try to match all pairs, going from smallest to larger and removing pairs. If we match all pairs, we return the original array.\n\n**C++**\n```cpp\nvector<int> recoverArray(... | 30 | 4 | [] | 16 |
recover-the-original-array | Java Clean | java-clean-by-rexue70-orse | from N = 1000, we know we can try something similar to O(n2)\nwe find out K is actually a limited number, it would be the difference between first element with | rexue70 | NORMAL | 2021-12-26T04:37:15.129006+00:00 | 2021-12-28T06:16:52.776431+00:00 | 1,559 | false | from N = 1000, we know we can try something similar to O(n2)\nwe find out K is actually a limited number, it would be the difference between first element with all the rest number, one by one, when we have this list of k, we can try them one by one.\n\nwhen we have a possible k to guess, we will see if both low (nums[i... | 21 | 1 | ['Java'] | 4 |
recover-the-original-array | Easy to Understand Explanation with C++ Code || Multiset TLE Why? | easy-to-understand-explanation-with-c-co-leq8 | Question Summary - There is an array arr. You created two different arrays, say Low and High. Low contains all the elements of arr but all the elements are decr | rupakk | NORMAL | 2021-12-26T05:29:33.740088+00:00 | 2022-01-02T06:04:23.807966+00:00 | 2,015 | false | Question Summary - There is an array arr. You created two different arrays, say Low and High. Low contains all the elements of arr but all the elements are decremented by a positive no k. Same as Low, High contains all the elements of arr but they are incremented by k. You are given an array which contains all the elem... | 20 | 2 | ['C'] | 5 |
recover-the-original-array | ✅ [Python] Simple O(N^2) Solution || Detailed Explanation || Beginner Friendly | python-simple-on2-solution-detailed-expl-98zd | PLEASE UPVOTE if you like \uD83D\uDE01 If you have any question, feel free to ask. \n\nThe time complexity is O(N^2)\n\n\nclass Solution(object):\n def recov | linfq | NORMAL | 2021-12-26T16:27:59.369331+00:00 | 2021-12-27T03:59:22.600744+00:00 | 790 | false | **PLEASE UPVOTE if you like** \uD83D\uDE01 **If you have any question, feel free to ask.** \n\n`The time complexity is O(N^2)`\n\n```\nclass Solution(object):\n def recoverArray(self, nums):\n nums.sort()\n mid = len(nums) // 2\n # All possible k are (nums[j] - nums[0]) // 2, otherwise there is ... | 17 | 1 | ['Python'] | 4 |
recover-the-original-array | C++ Very Easy Solution | c-very-easy-solution-by-rishabh_devbansh-h2tw | Approach\n\nThe idea is very simple, we know the minimum element in the permutation belongs to lower and maximum element belongs to higher. So , we\'ll push min | rishabh_devbanshi | NORMAL | 2021-12-26T10:21:12.871675+00:00 | 2021-12-26T12:56:48.684679+00:00 | 1,375 | false | ## Approach\n\nThe idea is very simple, we know the minimum element in the permutation belongs to lower and maximum element belongs to higher. So , we\'ll push minimum element in our ans array, then for each remaining element we\'ll try it to make first element of b and find k as\n\n\t\t\t\t\t\t\t\thigher[i] - lower[i]... | 16 | 1 | ['C'] | 3 |
recover-the-original-array | ✅Detailed Explanation || Binary Search || C++ , java | detailed-explanation-binary-search-c-jav-ylcc | Read the whole post and solution code to get clear understanding.\n\nQuestion explanation :\nAlice has array nums with n elements which is not given us. He choo | VishalSahu18 | NORMAL | 2021-12-26T18:53:40.716470+00:00 | 2023-03-05T09:11:13.362337+00:00 | 951 | false | *Read the whole post and solution code to get clear understanding.*\n\n**Question explanation :**\nAlice has array nums with n elements which is not given us. He chooses a **positive** integer **k** and created two new array of **same size** from the array he has\n1.) **lower array**\n2.) **higher array**\n\nfor each *... | 13 | 0 | ['Binary Tree'] | 2 |
recover-the-original-array | [Python3] brute-force | python3-brute-force-by-ye15-o2kx | Please check out this commit for solutions of weely 273. \n\n\nclass Solution:\n def recoverArray(self, nums: List[int]) -> List[int]:\n nums.sort()\n | ye15 | NORMAL | 2021-12-26T04:01:49.429901+00:00 | 2021-12-26T15:17:34.063389+00:00 | 867 | false | Please check out this [commit](https://github.com/gaosanyong/leetcode/commit/338b3e50d12cc0067b8b85e8e27c1b0c10fd91c6) for solutions of weely 273. \n\n```\nclass Solution:\n def recoverArray(self, nums: List[int]) -> List[int]:\n nums.sort()\n cnt = Counter(nums)\n for i in range(1, len(nums)): ... | 12 | 0 | ['Python3'] | 4 |
recover-the-original-array | [Java] Explained: check valid K with two pointers, 6ms beats 100% | java-explained-check-valid-k-with-two-po-429f | Let\'s assume that the original array was [x, y, z] (x <= y <= z), and after subtracting and adding k we\'ve got an array of pairs [x-k, x+k, y-k, y+k, z-k, z+k | bl2003 | NORMAL | 2021-12-26T06:25:37.330563+00:00 | 2021-12-26T23:46:04.813075+00:00 | 539 | false | Let\'s assume that the original array was `[x, y, z] (x <= y <= z)`, and after subtracting and adding `k` we\'ve got an array of pairs `[x-k, x+k, y-k, y+k, z-k, z+k]`. We can make the following observations:\n1. The smallest number `x` in the original array will produce the smallest number `x - k` in the generated arr... | 9 | 0 | ['Java'] | 1 |
recover-the-original-array | Beats 100% on runtime [EXPLAINED] | beats-100-on-runtime-explained-by-r9n-3st2 | Intuition\nUnderstanding how the original array can be derived from the modified arrays, where each element has been adjusted by a positive integer k. Since we | r9n | NORMAL | 2024-11-04T05:55:53.355349+00:00 | 2024-11-04T05:55:53.355383+00:00 | 83 | false | # Intuition\nUnderstanding how the original array can be derived from the modified arrays, where each element has been adjusted by a positive integer k. Since we know how the modified values relate to the original ones, we can reverse-engineer the original values.\n\n# Approach\nSort the given array, iterate through po... | 7 | 0 | ['Array', 'Hash Table', 'Two Pointers', 'Sorting', 'Enumeration', 'C#'] | 0 |
recover-the-original-array | O(N^2) Time solution without hashMap | on2-time-solution-without-hashmap-by-nik-5f8y | The idea is similar to most of the Solutions on Discuss page, Only difference is function used to find the original array given a value of k.\nInstead of using | nikhilmishra1211 | NORMAL | 2021-12-29T15:26:04.003437+00:00 | 2021-12-29T15:26:04.003480+00:00 | 506 | false | The idea is similar to most of the Solutions on Discuss page, Only difference is function used to find the original array given a value of k.\nInstead of using a Hashmap or multiset. This solution uses to 2-pointer approch which is guaranteed O(N) time, getting rid of hash colliosions in case of HashMap.\n\n```\n\nclas... | 6 | 0 | ['Two Pointers', 'C'] | 1 |
recover-the-original-array | C++ || Simple Maths || With Explanation | c-simple-maths-with-explanation-by-matic-zqvy | ```\n/ so array elements are of form\nA-K B-K C-K A+K B+K C+K but we dont know actual sequence\nsubstrate A-K from the whole so\n0 B- | Matic001 | NORMAL | 2021-12-28T10:00:33.651184+00:00 | 2021-12-28T10:00:51.827044+00:00 | 603 | false | ```\n/* so array elements are of form\nA-K B-K C-K A+K B+K C+K but we dont know actual sequence\nsubstrate A-K from the whole so\n0 B-A C-A 2K B-A+2K C-A+2K\nso we calculate 2k that is the Doublediff and store in doublediff vector \n\nso we put all possibel value of double diff in... | 6 | 1 | [] | 0 |
recover-the-original-array | Java - find and check k fits or not || PriorityQueue | java-find-and-check-k-fits-or-not-priori-dapn | \nclass Solution {\n public int[] recoverArray(int[] nums) {\n \n \tint i,n=nums.length;\n \tint ans[]=new int[n/2];\n \tArrays.sort(nums);\n | pgthebigshot | NORMAL | 2021-12-26T04:01:55.979233+00:00 | 2021-12-26T04:16:35.592613+00:00 | 604 | false | ````\nclass Solution {\n public int[] recoverArray(int[] nums) {\n \n \tint i,n=nums.length;\n \tint ans[]=new int[n/2];\n \tArrays.sort(nums);\n \tPriorityQueue<Integer> pq=new PriorityQueue<>();\n \tfor(i=0;i<n;i++)\n \t\tpq.add(nums[i]);\n \tfor(i=1;i<n;i++)\n \t{\n \t\tPriorityQ... | 5 | 1 | ['Heap (Priority Queue)', 'Java'] | 2 |
recover-the-original-array | C++ Simple Solution using queue | c-simple-solution-using-queue-by-deepaks-m0q1 | Approach\nWe need to find K such that orginalArray[i] - k , orginalArray[i] + k both exist in the nums array but we have low and high arrays merged so we can sa | DeepakSharma72 | NORMAL | 2022-09-15T02:16:05.864505+00:00 | 2022-09-15T02:18:24.193315+00:00 | 389 | false | **Approach**\nWe need to find **K** such that orginalArray[i] - k , orginalArray[i] + k both exist in the *nums* array but we have *low* and *high* arrays merged so we can say *high[i] - 2k = low[i]*.Since *N* is just 1000 we can try to find elements in low and high arrays for all possible values of *K*.\n\n```\nclass ... | 4 | 0 | ['Queue', 'C', 'Sorting'] | 2 |
recover-the-original-array | simple c++ solution with explanation(n^2) | simple-c-solution-with-explanationn2-by-fskl5 | since it\'s given that atleast one valid answer is always possible , therefore for every index i of array there is one index j (i!=j) \nsuch that |array[ j | zombiedub | NORMAL | 2021-12-26T04:01:40.976288+00:00 | 2021-12-26T04:03:59.436961+00:00 | 345 | false | since it\'s given that atleast one valid answer is always possible , therefore for every index i of array there is one index j (i!=j) \nsuch that |array[ j ] - array[ i ] | == 2*k ,\nwhere k is the positive integer given in question.\n\nlets first sort the array to simplify things for us.\n\nnow let\'s say we star... | 4 | 0 | ['C'] | 0 |
recover-the-original-array | C++ | O(N^2) | Identify all K and use the concept of "954. Array of Doubled Pairs" | c-on2-identify-all-k-and-use-the-concept-1sk2 | Logic:\nSimilar to "954. Array of Doubled Pairs" or "2007. Find Original Array From Doubled Array"\n\nStep 1: Identify the possible K\'s\nStep 2: Maintain a cou | kshitijSinha | NORMAL | 2022-01-16T13:58:32.635861+00:00 | 2022-01-16T13:58:32.635902+00:00 | 227 | false | Logic:\nSimilar to "[954. Array of Doubled Pairs](https://leetcode.com/problems/array-of-doubled-pairs/)" or "[2007. Find Original Array From Doubled Array](https://leetcode.com/problems/find-original-array-from-doubled-array/)"\n\nStep 1: Identify the possible K\'s\nStep 2: Maintain a counter of all values of array\nS... | 3 | 0 | [] | 0 |
recover-the-original-array | Java : check all possible Ks | java-check-all-possible-ks-by-dimitr-fox4 | nums contains permutation of {a-k,a+k, b-k,b+k,...,z-k,z+k}\n- we can sort permutation array and find all possible K : (nums[i]-nums[0])/2, for i>=1 and even (n | dimitr | NORMAL | 2021-12-28T07:51:23.845936+00:00 | 2021-12-30T10:38:30.218773+00:00 | 170 | false | - **nums** contains permutation of **{a-k,a+k, b-k,b+k,...,z-k,z+k}**\n- we can sort permutation array and find all possible **K** : **(nums[i]-nums[0])/2**, for **i>=1** and **even (nums[i]-nums[0])**\n- we can map all occurrences of values into **value:count**\n- we have to iterate though all possible **K**s and chec... | 3 | 0 | [] | 1 |
recover-the-original-array | JAVA | HashMap trying all possible k | java-hashmap-trying-all-possible-k-by-my-hd3q | After sorting, k can be (nums[i]-nums[0])/2 for any i in 1 ~ n, then use a HashMap to check if such k is valid.\n\n\nclass Solution {\n Map<Integer, Integer> | myih | NORMAL | 2021-12-26T04:01:09.973693+00:00 | 2021-12-26T04:01:55.416534+00:00 | 304 | false | After sorting, k can be (nums[i]-nums[0])/2 for any i in 1 ~ n, then use a HashMap<element, count> to check if such k is valid.\n\n```\nclass Solution {\n Map<Integer, Integer> countMap;\n public int[] recoverArray(int[] nums) {\n int n = nums.length/2;\n Arrays.sort(nums);\n countMap = new H... | 3 | 0 | [] | 0 |
recover-the-original-array | Simple Solution using multiset!!!⚡🔥💕💕 | simple-solution-using-multiset-by-yashpa-3pow | \n# Code\n\nclass Solution {\npublic:\n bool f(multiset<int>ms,int n,int k,vector<int>&ans){\n while(!ms.empty()){\n int smallest1=*ms.begi | yashpadiyar4 | NORMAL | 2023-05-24T18:15:03.205619+00:00 | 2023-05-24T18:15:03.205661+00:00 | 75 | false | \n# Code\n```\nclass Solution {\npublic:\n bool f(multiset<int>ms,int n,int k,vector<int>&ans){\n while(!ms.empty()){\n int smallest1=*ms.begin();\n int smallest2=smallest1+2*k;\n if(ms.find(smallest2)==ms.end())return false;\n ans.push_back(smallest1+k);\n ... | 2 | 0 | ['C++'] | 0 |
recover-the-original-array | Java HashMap O(n^2) with comments and explaination | java-hashmap-on2-with-comments-and-expla-j7n2 | \n\nThe idea is smallest element in the array would always be part of lower array so we can fix that element and iterate through rest of array to find possible | pathey | NORMAL | 2022-10-11T16:29:48.433654+00:00 | 2022-10-11T16:29:48.433696+00:00 | 427 | false | \n\nThe idea is smallest element in the array would always be part of lower array so we can fix that element and iterate through rest of array to find possible k values, k would be equal to (nums[i]-nums[0])/2, now the next step is to verify if the taken k value is correct or not. For that we iterate over the array aga... | 2 | 0 | ['Java'] | 1 |
recover-the-original-array | Step By Step Explaination | step-by-step-explaination-by-bhavya0020-v6m6 | Logic\nThis Problem is all about finding K which is subtracted from original array (lower[i] = ar[i] - K) or added to the original array (higher[i] = ar[i] + K) | bhavya0020 | NORMAL | 2022-01-06T09:40:47.827658+00:00 | 2022-01-06T09:40:47.827707+00:00 | 194 | false | ## Logic\nThis Problem is all about finding K which is subtracted from original array (lower[i] = ar[i] - K) or added to the original array (higher[i] = ar[i] + K)\n\n## Code\n```\nclass Solution {\npublic:\n vector<int> recoverArray(vector<int>& nums) {\n int n = nums.size();\n// step - 1: arrange el... | 2 | 0 | ['C'] | 0 |
recover-the-original-array | Need Help , O(n^2) Sol getting tle | need-help-on2-sol-getting-tle-by-kingray-rhjn | I am checking for all the possible differences which may give answer in O(n) so expected time complexity should be O(n^2) but its getting tle , can someone poin | KingRayuga | NORMAL | 2021-12-26T04:08:36.959119+00:00 | 2021-12-26T04:08:36.959148+00:00 | 157 | false | I am checking for all the possible differences which may give answer in O(n) so expected time complexity should be O(n^2) but its getting tle , can someone point out the mistake\n```\nclass Solution {\npublic:\n vector<int> recoverArray(vector<int>& nums) {\n set<int>diff;\n int n = nums.size();\n ... | 2 | 0 | [] | 1 |
recover-the-original-array | can't we use binary search on K ?? need help || why this fails | cant-we-use-binary-search-on-k-need-help-5d0j | i did binary search on value of k (0 to (maxelement-minelement)) \nif more elements r less than our current assumed k than high=k-1\nelse low=k+1\n\nANSWER:\nth | meayush912 | NORMAL | 2021-12-26T04:07:22.827177+00:00 | 2021-12-26T04:20:38.400277+00:00 | 156 | false | i did binary search on value of k (0 to (maxelement-minelement)) \nif more elements r less than our current assumed k than high=k-1\nelse low=k+1\n\nANSWER:\nthis fails because our function here is not monotonic in nature\ni thought maybe counting elements will be enough to steer in one direction but it doesn\'t gauran... | 2 | 0 | [] | 2 |
recover-the-original-array | C++ solution, use brute-foce to try each k. | c-solution-use-brute-foce-to-try-each-k-k56f8 | \n\n1. sort the array\n2. because nums[0] is orginal[0] - k, then we can assume that nums[i] (i > 0) is original[0] + k, then k = (nums[i] - nums[0]) / 2\n3. tr | 11235813 | NORMAL | 2021-12-26T04:00:38.371735+00:00 | 2021-12-27T04:22:14.955516+00:00 | 379 | false | \n\n1. sort the array\n2. because nums[0] is orginal[0] - k, then we can assume that nums[i] (i > 0) is original[0] + k, then k = `(nums[i] - nums[0]) / 2`\n3. try all k to find the valid answer.\n \n```\nclass Solution {\npublic:\n vector<int> recoverArray(vector<int>& nums) {\n sort(nums.begin(), nums.en... | 2 | 1 | [] | 3 |
recover-the-original-array | Just a runnable solution | just-a-runnable-solution-by-ssrlive-tp1c | Code\n\nimpl Solution {\n pub fn recover_array(nums: Vec<i32>) -> Vec<i32> {\n let mut nums = nums;\n nums.sort();\n let n = nums.len() | ssrlive | NORMAL | 2023-03-04T03:00:39.984971+00:00 | 2023-03-04T03:00:39.985004+00:00 | 12 | false | # Code\n```\nimpl Solution {\n pub fn recover_array(nums: Vec<i32>) -> Vec<i32> {\n let mut nums = nums;\n nums.sort();\n let n = nums.len() / 2;\n let a = nums[0];\n let mut v1 = Vec::with_capacity(n);\n let mut v2 = Vec::with_capacity(n);\n for i in 1..nums.len() {\... | 1 | 0 | ['Rust'] | 0 |
recover-the-original-array | Simple C++ Solution | simple-c-solution-by-_mrvariable-wsgc | \nclass Solution {\npublic:\n vector<int> recoverArray(vector<int>& nums) {\n int n = nums.size();\n sort(nums.begin(), nums.end());\n u | _MrVariable | NORMAL | 2022-08-03T05:15:34.571748+00:00 | 2022-08-03T05:15:34.571797+00:00 | 264 | false | ```\nclass Solution {\npublic:\n vector<int> recoverArray(vector<int>& nums) {\n int n = nums.size();\n sort(nums.begin(), nums.end());\n unordered_map<int, int> mp, mpp;\n for(int i = 0; i < nums.size(); i++) {\n mp[nums[i]]++;\n mpp[nums[i]]++;\n }\n ... | 1 | 0 | ['Greedy', 'C'] | 0 |
recover-the-original-array | Go // O(n^2) // Trying all values of k // Full explanation with optimizations | go-on2-trying-all-values-of-k-full-expla-hcs6 | Approach:\nThe problem is twofold -- firstly, we need to find a valid value of k, and secondly, we need to pair terms up in a way such that each pair has a diff | cyclic | NORMAL | 2022-07-24T08:10:59.778946+00:00 | 2022-07-24T08:10:59.778976+00:00 | 85 | false | **Approach:**\nThe problem is twofold -- firstly, we need to find a valid value of `k`, and secondly, we need to pair terms up in a way such that each pair has a difference of `2k`.\n\nSo, how can we find values of `k` to test? Well, if a value of `k` is valid, two numbers in `nums` must have difference `2k`, since one... | 1 | 0 | ['Sorting', 'Go'] | 0 |
recover-the-original-array | Easy to understand Hashmap solution C++ | easy-to-understand-hashmap-solution-c-by-3718 | \nclass Solution {\npublic:\n vector<int> recoverArray(vector<int>& nums) {\n int n=nums.size();\n sort(nums.begin(),nums.end());\n \n | bhavit123 | NORMAL | 2022-06-08T11:14:53.910575+00:00 | 2022-06-08T11:15:50.119263+00:00 | 424 | false | ```\nclass Solution {\npublic:\n vector<int> recoverArray(vector<int>& nums) {\n int n=nums.size();\n sort(nums.begin(),nums.end());\n \n map<int,int> mp;\n for(int i=0;i<n;i++)\n mp[nums[i]]++;\n int l=0;\n int r=(n/2);\n int gap=0;\n while(l... | 1 | 0 | ['C', 'C++'] | 1 |
recover-the-original-array | [26ms] || Compression solution || With Explanation|| C++ | 26ms-compression-solution-with-explanati-aus2 | \nclass Solution {\npublic:\n /*\n Hint:\n PLEASE AS A PREREQUISITE DO SOLVE: https://leetcode.com/problems/find-original-array-from-double | i_see_you | NORMAL | 2022-05-10T20:24:32.182158+00:00 | 2022-05-10T20:35:22.275271+00:00 | 160 | false | ```\nclass Solution {\npublic:\n /*\n Hint:\n PLEASE AS A PREREQUISITE DO SOLVE: https://leetcode.com/problems/find-original-array-from-doubled-array/ \n 1. There are basically 2 types of elements (X + k) or (X - k), and the problem is you don\'t know which is which or do you?\n ... | 1 | 0 | [] | 0 |
recover-the-original-array | Easy to understand | All Possible K | TC - O(k*n) | k is all possible k values | easy-to-understand-all-possible-k-tc-okn-v6wt | cpp\nclass Solution {\npublic:\n vector<int> recoverArray(vector<int>& nums) {\n int n = nums.size(); \n if(n==2) return {(nums[0]+nums[1])/2}; | bgoel4132 | NORMAL | 2022-02-13T17:32:16.659284+00:00 | 2022-02-13T17:32:16.659332+00:00 | 220 | false | ```cpp\nclass Solution {\npublic:\n vector<int> recoverArray(vector<int>& nums) {\n int n = nums.size(); \n if(n==2) return {(nums[0]+nums[1])/2};\n sort(nums.begin(), nums.end()); \n \n set<int> lower; \n for(int i = 1; i < n; i++) {\n if((nums[i]-nums[0])%2==0 a... | 1 | 0 | ['C'] | 0 |
recover-the-original-array | Python Hash Table, sorting with detailed explanation, fast and efficient | python-hash-table-sorting-with-detailed-yv4s4 | \nclass Solution:\n def recoverArray(self, nums: List[int]) -> List[int]:\n counter = Counter(nums) # counter\n nums = sorted(counter) # sor | KC19920313 | NORMAL | 2022-02-02T18:00:59.833906+00:00 | 2022-02-02T18:01:49.543422+00:00 | 179 | false | ```\nclass Solution:\n def recoverArray(self, nums: List[int]) -> List[int]:\n counter = Counter(nums) # counter\n nums = sorted(counter) # sorted unique numbers\n\n hm = nums[-1] # the max number must be the max in the "higher" group\n for num in nums[:-1]: # test the co... | 1 | 0 | ['Hash Table', 'Sorting'] | 0 |
recover-the-original-array | Java O(N^2)|Pruning Same differences | java-on2pruning-same-differences-by-yu-n-d7hv | We can see the range of the array is so small. The largest array length is just 1000. So we can guess the k by two different indices elements, and then use hash | yu-niang-niang | NORMAL | 2022-01-22T01:34:42.768326+00:00 | 2022-01-22T02:09:10.265929+00:00 | 227 | false | We can see the range of the array is so small. The largest array length is just **1000**. So we can guess the **k** by two different indices elements, and then use hash map to check the answer is right or not.\nSpecifically, the smallest element must be in the lower array,if it in the higher array, we can not find the... | 1 | 0 | ['Java'] | 0 |
recover-the-original-array | Golang simple brute force solution | golang-simple-brute-force-solution-by-tj-tky7 | go\nfunc recoverArray(nums []int) []int {\n\tsort.Ints(nums)\n\tfor pairIndex0 := 1; pairIndex0 < len(nums); pairIndex0++ {\n\t\tif (nums[pairIndex0]-nums[0])%2 | tjucoder | NORMAL | 2021-12-28T04:37:30.665568+00:00 | 2021-12-28T04:37:30.665602+00:00 | 108 | false | ```go\nfunc recoverArray(nums []int) []int {\n\tsort.Ints(nums)\n\tfor pairIndex0 := 1; pairIndex0 < len(nums); pairIndex0++ {\n\t\tif (nums[pairIndex0]-nums[0])%2 != 0 {\n\t\t\tcontinue\n\t\t}\n\t\tk := (nums[pairIndex0] - nums[0]) / 2\n\t\tif k == 0 {\n\t\t\tcontinue\n\t\t}\n\t\tpairs := make(map[int]int, len(nums))\... | 1 | 0 | ['Go'] | 0 |
recover-the-original-array | Super easy to understand C++ Code, beat 100% | super-easy-to-understand-c-code-beat-100-9a5c | Idea is straight forward - try every possible k.\n1. First we sort array and get minimum value - minV in this array, then try all possible high value of minV to | dogmimi | NORMAL | 2021-12-27T13:51:09.155646+00:00 | 2021-12-27T13:51:09.155677+00:00 | 241 | false | Idea is straight forward - try every possible k.\n1. First we sort array and get minimum value - minV in this array, then try all possible `high` value of minV to calculate k.\nTo get k, minV plus its high value s hould be even, and k can only be larger than 0.\n2. Then we need to verify if k is valid. Here I use a `us... | 1 | 0 | ['Two Pointers', 'Greedy', 'C'] | 1 |
recover-the-original-array | Java solution using 2 pointer along with every possible value of k (11ms) | java-solution-using-2-pointer-along-with-zqpt | \nclass Solution {\n \n int[] res;\n public int[] recoverArray(int[] nums) {\n int n = nums.length;\n Arrays.sort(nums);\n ArrayLi | akshobhyapal | NORMAL | 2021-12-27T12:51:23.106393+00:00 | 2021-12-27T12:51:52.454323+00:00 | 157 | false | ```\nclass Solution {\n \n int[] res;\n public int[] recoverArray(int[] nums) {\n int n = nums.length;\n Arrays.sort(nums);\n ArrayList<Integer> diffs = new ArrayList<>();\n int smallest = nums[0];\n for(int i = 1; i < n; i++){\n int k =(nums[i] - smallest) / 2;\n ... | 1 | 0 | ['Two Pointers', 'Java'] | 0 |
recover-the-original-array | Python O(N^2) | python-on2-by-miaomicode-dp20 | ```\nclass Solution:\n def recoverArray(self, nums: List[int]) -> List[int]:\n n = int(len(nums) / 2)\n nums.sort() \n \n | miaomicode | NORMAL | 2021-12-26T23:56:03.320923+00:00 | 2021-12-26T23:56:03.320955+00:00 | 75 | false | ```\nclass Solution:\n def recoverArray(self, nums: List[int]) -> List[int]:\n n = int(len(nums) / 2)\n nums.sort() \n \n for i in range(1, n * 2):\n k = nums[i] - nums[0]\n if k != 0 and not k % 2:\n higher = collections.defaultdict(int)\n ... | 1 | 0 | [] | 0 |
recover-the-original-array | Check common possible k from both sides[Java][8ms][100%] | check-common-possible-k-from-both-sidesj-fqta | Idea\nIf we sort nums, then nums[0] must be is the lower value of the smallest value of the original array(min(arr) - k).\nThen, we can check the differences nu | akokoz | NORMAL | 2021-12-26T20:24:26.674524+00:00 | 2021-12-26T20:25:04.968319+00:00 | 81 | false | **Idea**\nIf we sort `nums`, then `nums[0]` must be is the `lower` value of the smallest value of the original array(`min(arr) - k`).\nThen, we can check the differences `nums[i] - nums[0]` for the one that matches all pairs. The differences to consider must be positive and even.\n\n**Optimizations**\n1. We can check ... | 1 | 0 | ['Greedy', 'Java'] | 0 |
recover-the-original-array | (C++) 2122. Recover the Original Array | c-2122-recover-the-original-array-by-qee-thj9 | \n\nclass Solution {\npublic:\n vector<int> recoverArray(vector<int>& nums) {\n sort(nums.begin(), nums.end()); \n \n map<int, int> cnt; | qeetcode | NORMAL | 2021-12-26T17:33:11.045080+00:00 | 2021-12-26T17:33:11.045138+00:00 | 226 | false | \n```\nclass Solution {\npublic:\n vector<int> recoverArray(vector<int>& nums) {\n sort(nums.begin(), nums.end()); \n \n map<int, int> cnt; \n for (auto& x : nums) ++cnt[x]; \n \n vector<int> ans; \n for (int i = 1; i < nums.size(); ++i) {\n int diff = nums... | 1 | 0 | ['C'] | 0 |
recover-the-original-array | golang | golang-by-eesketit-uorv | we know the smallest number in nums, is the smallest number in result + k. From there, try out all possible k from nums[i] - nums[0].\n\n\nfunc recoverArray(num | eesketit | NORMAL | 2021-12-26T09:47:13.975408+00:00 | 2021-12-26T09:47:13.975441+00:00 | 54 | false | we know the smallest number in nums, is the smallest number in result + k. From there, try out all possible k from nums[i] - nums[0].\n\n```\nfunc recoverArray(nums []int) []int {\n sort.Ints(nums)\n freq := make(map[int]int)\n for _, n := range nums {\n freq[n]++\n }\n for i := 1; i<len(nums); i+... | 1 | 0 | [] | 1 |
recover-the-original-array | Java | Sort and try all Ks | brute force with two pointers (6ms) | java-sort-and-try-all-ks-brute-force-wit-7qpi | Sort the mixed up array and use two pointers within it (i1, i2) to point to elements of the smaller and larger arrays.\nTry all possible Ks: the first element o | prezes | NORMAL | 2021-12-26T06:32:21.391094+00:00 | 2021-12-26T07:46:10.283941+00:00 | 98 | false | Sort the mixed up array and use two pointers within it (i1, i2) to point to elements of the smaller and larger arrays.\nTry all possible Ks: the first element of the larger array after sorting can be at index in range [1...n]. K is then equal to (nums[i2]-nums[i1])/2 (must be positive).\n```\n // i - index of resultin... | 1 | 0 | [] | 0 |
recover-the-original-array | [Python3] Try All Valid K Values | python3-try-all-valid-k-values-by-simone-7e6b | ```\nclass Solution:\n def recoverArray(self, nums):\n self.n, self.nums = len(nums) // 2, sorted(nums)\n\n small = self.nums[0]\n for x | simonesestili | NORMAL | 2021-12-26T04:53:14.846269+00:00 | 2021-12-26T04:57:19.845913+00:00 | 142 | false | ```\nclass Solution:\n def recoverArray(self, nums):\n self.n, self.nums = len(nums) // 2, sorted(nums)\n\n small = self.nums[0]\n for x in self.nums[1:]:\n k = x - small # this represents 2 * k from the problem statement\n if k % 2 or not k: continue\n temp = se... | 1 | 0 | ['Python3'] | 0 |
recover-the-original-array | Multiset O(n^2logn) Time Complexity | multiset-on2logn-time-complexity-by-yash-0kcl | Intuition
Find all possible k values.
We can do it by fixing one element and iterating aover all elements and getting corresponding k value thinking that this i | yash559 | NORMAL | 2025-01-31T02:12:31.365988+00:00 | 2025-01-31T02:12:31.365988+00:00 | 10 | false | # Intuition
- Find all possible k values.
- We can do it by fixing one element and iterating aover all elements and getting corresponding k value thinking that this is a possible result.
- Now, check whether this k matches.
- Now we need an efficient data structure which can store the **duplicates and as well deletion ... | 0 | 0 | ['C++'] | 0 |
recover-the-original-array | 2122. Recover the Original Array | 2122-recover-the-original-array-by-g8xd0-dszk | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | G8xd0QPqTy | NORMAL | 2025-01-18T03:09:28.900147+00:00 | 2025-01-18T03:09:28.900147+00:00 | 3 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['C#'] | 0 |
recover-the-original-array | Checking pairs | checking-pairs-by-vats_lc-a7f5 | Code | vats_lc | NORMAL | 2025-01-09T05:11:58.756918+00:00 | 2025-01-09T05:11:58.756918+00:00 | 8 | false | # Code
```cpp []
class Solution {
public:
vector<int> recoverArray(vector<int>& a) {
int n = a.size(), diff = 0;
sort(a.begin(), a.end());
map<int, int> mpp;
for (int i = 0; i < n; i++)
mpp[a[i]]++;
for (int i = 1; i < n; i++) {
diff = a[i] - a[0];
... | 0 | 0 | ['C++'] | 0 |
recover-the-original-array | SImple hashmap solution | simple-hashmap-solution-by-risabhuchiha-3h58 | null | risabhuchiha | NORMAL | 2024-12-26T12:34:31.895413+00:00 | 2024-12-26T12:34:31.895413+00:00 | 5 | false |
```java []
class Solution {
public int[] recoverArray(int[] nums) {
Arrays.sort(nums);
int s=nums[0];
for(int i=1;i<nums.length;i++){
int k=(nums[i]-s);
if(k==0)continue;
if(k%2!=0)continue;
k=k/2;
//if(k==0)continue... | 0 | 0 | ['Java'] | 0 |
recover-the-original-array | Recover the Original Array | recover-the-original-array-by-naeem_abd-eb0e | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Naeem_ABD | NORMAL | 2024-12-03T04:55:38.420737+00:00 | 2024-12-03T04:55:38.420772+00:00 | 2 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['JavaScript'] | 0 |
recover-the-original-array | Python (Simple Hashmap) | python-simple-hashmap-by-rnotappl-qyeg | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | rnotappl | NORMAL | 2024-11-02T15:10:21.757536+00:00 | 2024-11-02T15:10:21.757567+00:00 | 9 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Python3'] | 0 |
recover-the-original-array | 2122. Recover the Original Array.cpp | 2122-recover-the-original-arraycpp-by-20-cg7p | Code\n\nclass Solution {\npublic:\n vector<int> recoverArray(vector<int>& nums) {\n sort(nums.begin(), nums.end()); \n \n map<int, int> | 202021ganesh | NORMAL | 2024-11-01T10:53:21.078503+00:00 | 2024-11-01T10:53:21.078532+00:00 | 0 | false | **Code**\n```\nclass Solution {\npublic:\n vector<int> recoverArray(vector<int>& nums) {\n sort(nums.begin(), nums.end()); \n \n map<int, int> cnt; \n for (auto& x : nums) ++cnt[x]; \n \n vector<int> ans; \n for (int i = 1; i < nums.size(); ++i) {\n int dif... | 0 | 0 | ['C'] | 0 |
recover-the-original-array | Python (Simple Hashmap) | python-simple-hashmap-by-rnotappl-zvd0 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | rnotappl | NORMAL | 2024-10-31T08:26:14.614646+00:00 | 2024-10-31T08:26:14.614673+00:00 | 6 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Python3'] | 0 |
recover-the-original-array | Easy Solution || try diff values of k | easy-solution-try-diff-values-of-k-by-ab-0zr9 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Abhi5114 | NORMAL | 2024-10-18T15:46:15.697573+00:00 | 2024-10-18T15:46:15.697602+00:00 | 2 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Java'] | 0 |
recover-the-original-array | Python (Simple Sorting + Hashmap) | python-simple-sorting-hashmap-by-rnotapp-y0ss | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | rnotappl | NORMAL | 2024-10-09T09:11:48.086965+00:00 | 2024-10-09T09:11:48.087001+00:00 | 5 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Python3'] | 0 |
recover-the-original-array | C# Greedy with Two Pointer Solution | c-greedy-with-two-pointer-solution-by-ge-w78v | Intuition\n- Describe your first thoughts on how to solve this problem. First Thoughts: The intuition behind solving this problem is to realize that the array | GetRid | NORMAL | 2024-10-07T15:37:16.856591+00:00 | 2024-10-07T15:37:16.856626+00:00 | 3 | false | # Intuition\n- <!-- Describe your first thoughts on how to solve this problem. -->First Thoughts: The intuition behind solving this problem is to realize that the array you are given (nums) is actually the result of performing an operation that involves an original array with a certain offset (k). The key challenge her... | 0 | 0 | ['Array', 'Hash Table', 'Two Pointers', 'Sorting', 'C#'] | 0 |
recover-the-original-array | ruby 2-liner | ruby-2-liner-by-_-k-mjj7 | ruby []\ndef recover_array(a) =\n\n a.sort!.uniq[1..].map{ 1>1&d=_1-a[0] and t=a.tally and break a.map{|x|\n t[x]-=1 and 1/~t[x+d]-=1 and x+d/2 if t[x]>0 } | _-k- | NORMAL | 2024-09-28T05:59:29.403852+00:00 | 2024-09-28T06:46:28.716516+00:00 | 5 | false | ```ruby []\ndef recover_array(a) =\n\n a.sort!.uniq[1..].map{ 1>1&d=_1-a[0] and t=a.tally and break a.map{|x|\n t[x]-=1 and 1/~t[x+d]-=1 and x+d/2 if t[x]>0 } rescue 0 }.compact\n``` | 0 | 0 | ['Ruby'] | 0 |
recover-the-original-array | [Python3] Just Working Code - 27.09.2024 | python3-just-working-code-27092024-by-pi-19wz | \npython3 [1 python3]\nclass Solution:\n def recoverArray(self, nums: List[int]) -> List[int]:\n nums.sort()\n cnt = Counter(nums)\n for | Piotr_Maminski | NORMAL | 2024-09-27T14:42:40.107781+00:00 | 2024-09-27T14:44:54.189657+00:00 | 7 | false | \n```python3 [1 python3]\nclass Solution:\n def recoverArray(self, nums: List[int]) -> List[int]:\n nums.sort()\n cnt = Counter(nums)\n for i in range(1, len(nums)): \n diff = nums[i] - nums[0]\n if diff and diff&1 == 0: \n ans = []\n freq = cn... | 0 | 0 | ['Python3'] | 0 |
recover-the-original-array | Python (Simple Maths) | python-simple-maths-by-rnotappl-lld4 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | rnotappl | NORMAL | 2024-07-24T13:57:03.521218+00:00 | 2024-07-24T13:57:03.521251+00:00 | 3 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Python3'] | 0 |
recover-the-original-array | Check for all possible Ks | check-for-all-possible-ks-by-akshay_gupt-tqu9 | Intuition\nCheck with all possible k.\n\n# Approach\nCheck of each possible pair what K could be. THen with one K try pairing exisitng numbers, if there\'s some | akshay_gupta_7 | NORMAL | 2024-07-12T18:44:52.427896+00:00 | 2024-07-12T18:44:52.427928+00:00 | 3 | false | # Intuition\nCheck with all possible k.\n\n# Approach\nCheck of each possible pair what K could be. THen with one K try pairing exisitng numbers, if there\'s some numbers which are pending and can\'t be paired, this K is not possibe.\n\n# Complexity\n- Time complexity:\n$$O(n^3)$$\n\n- Space complexity:\n$$O(n)$$\n\n\n... | 0 | 0 | ['Java'] | 0 |
recover-the-original-array | Greedy + Sorting + Hashmap 💯💯💯💯 Easy To understand!!!! With Comments | greedy-sorting-hashmap-easy-to-understan-kbmf | Approach\nFirst sort the nums, this way we can tell that nums[0] is lower[i] for some ith index in the original array.\nNow we know that higher[i] - lower[i] = | adira42004 | NORMAL | 2024-07-01T10:27:57.792424+00:00 | 2024-07-01T10:27:57.792462+00:00 | 41 | false | # Approach\nFirst sort the nums, this way we can tell that nums[0] is lower[i] for some ith index in the original array.\nNow we know that **higher[i] - lower[i] = 2*k.**\nTry for all possible value of 2*k fixing lower[i]==nums[0], now for each value of 2*k check wether this value is valid or not. This can be checked i... | 0 | 0 | ['C++'] | 0 |
recover-the-original-array | sorting + greedy + hashmap | sorting-greedy-hashmap-by-maxorgus-dvhg | the smallest number could pair with any number strictly larger than it so long as their difference is even, since n<=1000, we can enumerate them in one pass\n\n | MaxOrgus | NORMAL | 2024-06-19T02:30:31.197026+00:00 | 2024-06-19T02:30:31.197087+00:00 | 14 | false | the smallest number could pair with any number strictly larger than it so long as their difference is even, since n<=1000, we can enumerate them in one pass\n\nthen for every possible k stored, see if it is possible to pair all numbers with it. that is, go through the nums, see if there is any a - 2*k before it, if yes... | 0 | 0 | ['Hash Table', 'Greedy', 'Sorting', 'Python3'] | 0 |
recover-the-original-array | C++ Recovering an Array from a Given 2n Array Using Sorting and Hash Maps | c-recovering-an-array-from-a-given-2n-ar-4oll | Intuition\n\nThe problem requires recovering an array of n integers from a given array of 2n integers such that each element in the original array is the midpoi | orel12 | NORMAL | 2024-06-15T17:09:15.221815+00:00 | 2024-06-15T17:09:15.221841+00:00 | 15 | false | # Intuition\n\nThe problem requires recovering an array of n integers from a given array of 2n integers such that each element in the original array is the midpoint of two elements in the given array. We need to determine a value k such that when adding and subtracting k from each element in the recovered array, the re... | 0 | 0 | ['C++'] | 0 |
recover-the-original-array | Elixir sort then O(n^2) | elixir-sort-then-on2-by-minamikaze392-wtdz | Code\n\ndefmodule Solution do\n @spec recover_array(nums :: [integer]) :: [integer]\n def recover_array(nums) do\n n = length(nums) |> div(2)\n list = E | Minamikaze392 | NORMAL | 2024-05-31T14:10:37.133391+00:00 | 2024-05-31T14:10:37.133453+00:00 | 0 | false | # Code\n```\ndefmodule Solution do\n @spec recover_array(nums :: [integer]) :: [integer]\n def recover_array(nums) do\n n = length(nums) |> div(2)\n list = Enum.sort(nums)\n find_original(list, list, n)\n end\n\n defp find_original(list = [a | _], [prev, b | tail], n) do\n with true <- b > prev,\n tr... | 0 | 0 | ['Sorting', 'Elixir'] | 0 |
recover-the-original-array | C++ Clear Solution with Queue | Beats 85% in Runtime and 79% in Memory | c-clear-solution-with-queue-beats-85-in-gx4yj | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n1. Sort nums[] and test | danieltseng | NORMAL | 2024-05-26T08:49:47.571268+00:00 | 2024-05-26T08:49:47.571286+00:00 | 13 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Sort ```nums[]``` and test every possible K by ```nums[i] - nums[0]```\n2. Conduct early termination if ```ele``` is greater than the smallest numbers by ```twoK```... | 0 | 0 | ['Array', 'Queue', 'Sorting', 'C++'] | 0 |
recover-the-original-array | limit candidate k's to those with at least n counts in all pairwise diffs | limit-candidate-ks-to-those-with-at-leas-im48 | Intuition & Approach\n Describe your approach to solving the problem. \nInstead of only computing candidate k\'s using the smallest element of nums, we compute | jyscao | NORMAL | 2024-05-21T17:29:30.279209+00:00 | 2024-05-21T17:29:30.279233+00:00 | 2 | false | # Intuition & Approach\n<!-- Describe your approach to solving the problem. -->\nInstead of only computing candidate `k`\'s using the smallest element of `nums`, we compute all pairwise differences between all elements of `nums`, while tracking their counts. Valid candidate `k`\'s must have counts of at least `n`, the ... | 0 | 0 | ['Sorting', 'Counting', 'Python3'] | 0 |
recover-the-original-array | rust 13ms simple solution with explain | rust-13ms-simple-solution-with-explain-b-w8fk | \n\n\n# Intuition\nSort the array. For the first item and any other item, their differenca can be a $2k$. For every possible $k$, verify the nums weather this $ | sovlynn | NORMAL | 2024-05-09T18:50:49.227679+00:00 | 2024-05-09T18:50:49.227706+00:00 | 0 | false | \n\n\n# Intuition\nSort the array. For the first item and any other item, their differenca can be a $2k$. For every possible $k$, verify the nums weather this $k$ can recover the array.\n\nSince the array i... | 0 | 0 | ['Rust'] | 0 |
recover-the-original-array | JS Solution | js-solution-by-nanlyn-0w77 | Code\n\n/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar recoverArray = function (nums) {\n nums.sort((a, b) => (a - b));\n\n for (let i = | nanlyn | NORMAL | 2024-05-04T17:42:31.152494+00:00 | 2024-05-04T17:42:31.152510+00:00 | 2 | false | # Code\n```\n/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar recoverArray = function (nums) {\n nums.sort((a, b) => (a - b));\n\n for (let i = 1; i <= nums.length / 2; i++) {\n let twiceK = nums[i] - nums[0];\n if (twiceK === 0 || twiceK % 2 === 1) continue;\n let result = [];... | 0 | 0 | ['JavaScript'] | 0 |
recover-the-original-array | C++ || CLEAN SHORT CODE || GREEDY | c-clean-short-code-greedy-by-gauravgeekp-1eb1 | \n\n# Code\n\nclass Solution {\npublic:\n vector<int> recoverArray(vector<int>& a) {\n sort(a.begin(),a.end());\n vector<int> v;\n for(i | Gauravgeekp | NORMAL | 2024-04-30T07:06:43.464497+00:00 | 2024-04-30T07:06:43.464533+00:00 | 17 | false | \n\n# Code\n```\nclass Solution {\npublic:\n vector<int> recoverArray(vector<int>& a) {\n sort(a.begin(),a.end());\n vector<int> v;\n for(int i=1;i<=a.size()/2;i++)\n if(a[i]-a[0]!=0 && a[i]-a[0]!=1 && (a[i]-a[0])%2==0) v.push_back(a[i]-a[0]);\n \n int n=a.size()/2;\n ... | 0 | 0 | ['C++'] | 0 |
recover-the-original-array | Easy to understand || Using map and sorting || c++ | easy-to-understand-using-map-and-sorting-gim0 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Yuvraj161 | NORMAL | 2024-04-13T11:42:03.140805+00:00 | 2024-04-13T11:42:03.140832+00:00 | 14 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n^2 log n)\n\n- Space complexity: O(n)\n\n# Code\n```\nclass Solution {\npublic:\n vector<int> recoverArray(vector<int>& nums) ... | 0 | 0 | ['Array', 'Hash Table', 'Math', 'Greedy', 'Sorting', 'Enumeration', 'C++'] | 0 |
recover-the-original-array | Clear typescript solution (beats 100%) | clear-typescript-solution-beats-100-by-i-e1bd | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | igor_muram | NORMAL | 2024-01-25T14:08:02.539836+00:00 | 2024-01-25T14:28:44.295275+00:00 | 4 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(n^2)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```\nfunction recoverArray(nums: number[]): number[] {\n nums = nums.sort((... | 0 | 0 | ['TypeScript'] | 0 |
recover-the-original-array | Try all possible k values | try-all-possible-k-values-by-user1675rq-lpnd | Intuition\nBrute force try all possible k values, don\'t try impossible solutions or duplicates.\n\n# Approach\nFirst get all the potential k values for the fir | user1675rQ | NORMAL | 2024-01-04T03:31:52.901999+00:00 | 2024-01-04T03:31:52.902023+00:00 | 2 | false | # Intuition\nBrute force try all possible k values, don\'t try impossible solutions or duplicates.\n\n# Approach\nFirst get all the potential k values for the first entry in the array, one of them must be the right one.\n\nNext try to eliminate the pairs of values from the input corresponding to x - k, x + k recording ... | 0 | 0 | ['Go'] | 0 |
recover-the-original-array | Easy to understand CPP Solution || Using map and sorting | easy-to-understand-cpp-solution-using-ma-83zv | Intuition\nsort the nums array and store all the values of nums in the map\nthen calculate each posible value of k wrt nums[0].\n\n# Approach\n1 -> sort the nu | Joshiiii | NORMAL | 2023-11-17T10:18:14.025591+00:00 | 2023-11-17T10:18:14.025619+00:00 | 35 | false | # Intuition\nsort the nums array and store all the values of nums in the map\nthen calculate each posible value of k wrt nums[0].\n\n# Approach\n1 -> sort the nums array\n2 -> store all the values of nums in the map\n3 -> calculate all posible values of k\n4 -> check for all values of K that the solution exists or not... | 0 | 0 | ['Hash Table', 'Greedy', 'Sorting', 'C++'] | 0 |
recover-the-original-array | fast solution | fast-solution-by-punyreborn-b4t5 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | punyreborn | NORMAL | 2023-11-05T08:37:07.677809+00:00 | 2023-11-05T08:37:07.677826+00:00 | 3 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nsort: $$O(NlogN)$$\nfind: $$O(N)$$\n\n- Space complexity:\n<!-- Add your sp... | 0 | 0 | ['Go'] | 0 |
recover-the-original-array | My Solutions | my-solutions-by-hope_ma-con5 | 1. Use the std::unordered_map2. Don't use the std::unordered_map | hope_ma | NORMAL | 2023-07-14T04:56:08.480714+00:00 | 2025-02-01T00:58:17.022690+00:00 | 8 | false | **1. Use the `std::unordered_map`**
```
/**
* Time Complexity: O(n * n)
* Space Complexity: O(n)
* where `n` is the length of the vector `nums`
*/
class Solution {
public:
vector<int> recoverArray(vector<int> &nums) {
const int n = static_cast<int>(nums.size()) >> 1;
sort(nums.begin(), nums.end());
u... | 0 | 0 | ['C++'] | 0 |
recover-the-original-array | Simple approach | Using map and all possible values of K | C++ Solution | simple-approach-using-map-and-all-possib-sngv | Intuition\n Describe your first thoughts on how to solve this problesm. \nFinding all the possible values of K from the nums and then using map tp find out whet | ayushpanday612 | NORMAL | 2023-06-30T20:26:27.760902+00:00 | 2023-06-30T20:26:27.760940+00:00 | 68 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problesm. -->\nFinding all the possible values of K from the nums and then using map tp find out whether given vlue of K is posiible or not.\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nStep 1: Sort nums.\nStep 2: Storing a... | 0 | 0 | ['C++'] | 0 |
recover-the-original-array | 85+ in speed and memory using Python3 | 85-in-speed-and-memory-using-python3-by-ok5os | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | ranilmukesh | NORMAL | 2023-06-19T14:55:52.521841+00:00 | 2023-06-19T14:55:52.521860+00:00 | 30 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Python3'] | 0 |
recover-the-original-array | C++ Hash Table Sorting | c-hash-table-sorting-by-tejaswibishnoi-pq3o | Intuition\n Describe your first thoughts on how to solve this problem. \nThe first thought we may have by looking a this question may have binary search. But as | TejaswiBishnoi | NORMAL | 2023-05-24T17:08:07.960216+00:00 | 2023-05-24T17:08:07.960255+00:00 | 66 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe first thought we may have by looking a this question may have binary search. But as we see, we have no criteria to decide when to move left or right in binary search. But by looking at the question, we can see the relation between the... | 0 | 0 | ['Hash Table', 'Sorting', 'C++'] | 0 |
recover-the-original-array | Java || Like leetcode 954 and 2007 || HashMap || With comments | java-like-leetcode-954-and-2007-hashmap-maypl | // b <=============2122. Recover the Original Array ============>\n // https://leetcode.com/problems/recover-the-original-array/description/\n\n // Consid | JoseDJ2010 | NORMAL | 2023-05-07T03:10:09.570347+00:00 | 2023-05-07T03:10:09.570399+00:00 | 27 | false | // b <=============2122. Recover the Original Array ============>\n // https://leetcode.com/problems/recover-the-original-array/description/\n\n // Consider [a,b,c,d] to be the original array.\n // [a-k,b-k,c-k,d-k] will be the lower array\n // [a+k,b+k,c+k,d+k] will be the higher array.\n\n // Humne aga... | 0 | 0 | ['Java'] | 0 |
recover-the-original-array | Ruby Solution in O(n^2) (100%/100%) | ruby-solution-in-on2-100100-by-dtkalla-jxwd | Intuition\nIt\'s easy to check if a possible value of k works, and to create the array if you know k. Find all possible values of k, find one that works, and g | dtkalla | NORMAL | 2023-04-30T00:12:01.301432+00:00 | 2023-04-30T00:12:01.301477+00:00 | 15 | false | # Intuition\nIt\'s easy to check if a possible value of k works, and to create the array if you know k. Find all possible values of k, find one that works, and generate the array.\n\n# Approach\n1. Sort the numbers (to better iterate later)\n2. Find how often each number occurs in the array\n3. Find the possibilities ... | 0 | 0 | ['Ruby'] | 0 |
recover-the-original-array | Python Counter: Use it to its fullest. 98ms, fastest solution yet... for slow python. | python-counter-use-it-to-its-fullest-98m-ukxy | Intuition\n Describe your first thoughts on how to solve this problem. \nMany solutions here cleverly create a counter, and yet iterate through each num in the | cswartzell | NORMAL | 2023-04-21T05:41:15.581078+00:00 | 2023-04-21T06:00:57.534776+00:00 | 34 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nMany solutions here cleverly create a counter, and yet iterate through each num in the full array to subtract matching pairs. We can do a little better though. Since we *have* the counter, we can iterate through that instead and remove wh... | 0 | 0 | ['Python3'] | 0 |
recover-the-original-array | Python. Beats 100%. | python-beats-100-by-russdt-a8ns | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nsort nums\n\ncreate a d | russdt | NORMAL | 2022-12-30T21:55:04.121956+00:00 | 2022-12-30T21:55:04.121996+00:00 | 142 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nsort nums\n\ncreate a dictionary with Counter of all vals\n\ncreate a test array testing abs(nums[0] - nums[i]) for i in range(1,n//2+1)\n\nthe n//2+1 upperbound is in... | 0 | 0 | ['Python', 'Python3'] | 0 |
recover-the-original-array | Dart implementation, O(N^2) | dart-implementation-on2-by-yakiv_galkin-djkt | Intuition\nIf we sort the array, the very first(i.e. min) element will belong to the low array, while one of the i-th elements belongs to the high array.\nSo we | yakiv_galkin | NORMAL | 2022-12-13T02:47:09.898109+00:00 | 2022-12-13T02:47:09.898152+00:00 | 20 | false | # Intuition\nIf we sort the array, the very first(i.e. min) element will belong to the low array, while one of the i-th elements belongs to the high array.\nSo we can iterate trough difference b/w first and i-th element and check our array for the match.\n\n# Approach\nUse containers (splay tree map and hash map) to ef... | 0 | 0 | ['Dart'] | 0 |
recover-the-original-array | Python solution | python-solution-by-vincent_great-lsj4 | \ndef recoverArray(self, nums: List[int]) -> List[int]:\n\tm, cnter = min(nums), Counter(sorted(nums))\n\tfor x in cnter.keys():\n\t\td = x-m\n\t\tif d>0 and d% | vincent_great | NORMAL | 2022-10-28T11:02:03.720191+00:00 | 2022-10-28T11:02:03.720231+00:00 | 33 | false | ```\ndef recoverArray(self, nums: List[int]) -> List[int]:\n\tm, cnter = min(nums), Counter(sorted(nums))\n\tfor x in cnter.keys():\n\t\td = x-m\n\t\tif d>0 and d%2==0:\n\t\t\tcnt, arr = cnter.copy(), []\n\t\t\tfor n, v in cnt.items():\n\t\t\t\tif v:\n\t\t\t\t\tif v<=cnt[n+d]:\n\t\t\t\t\t\tarr.extend([n+d//2]*v)\n\t\t\... | 0 | 0 | [] | 0 |
recover-the-original-array | Two Solutions Explained Python | two-solutions-explained-python-by-sartha-yvey | Try all k\nTime: O(n^2)\n2 <= 2k <= max(nums) - min(nums)\nthe diff higher[i] - lower[i] == 2k, so even is important.\nsort the nums and try all differences num | sarthakBhandari | NORMAL | 2022-10-27T10:44:15.242280+00:00 | 2022-10-27T10:52:06.906798+00:00 | 73 | false | **Try all k**\n**Time: O(n^2)**\n2 <= 2*k <= max(nums) - min(nums)\nthe diff higher[i] - lower[i] == 2*k, so even is important.\nsort the nums and try all differences nums[i] - nums[0].\nYou can check if a difference is valid in O(N) time. Just use two pointers (i, j). \ni is a pointer for elements in lower and j is a ... | 0 | 0 | ['Hash Table', 'Sorting', 'Python'] | 0 |
recover-the-original-array | [Python] Sort and try every possible k while recover origin on the fly | python-sort-and-try-every-possible-k-whi-qcjr | \nfrom collections import defaultdict\n\nclass Solution:\n def recoverArray(self, nums: List[int]) -> List[int]:\n nums.sort()\n for i in range | cava | NORMAL | 2022-10-26T10:05:54.493253+00:00 | 2022-10-26T10:06:17.427146+00:00 | 22 | false | ```\nfrom collections import defaultdict\n\nclass Solution:\n def recoverArray(self, nums: List[int]) -> List[int]:\n nums.sort()\n for i in range(1, len(nums)):\n\t\t\t# skip the same k or k is odd\n if nums[i] == nums[i - 1] or (nums[i] - nums[0]) & 1: continue\n k = (nums[i] - ... | 0 | 0 | [] | 0 |
recover-the-original-array | C++ sort + 2 pointers beats 100% | c-sort-2-pointers-beats-100-by-bcb98801x-adxa | find all possible k\n2. sort nums\n3. iterate all possible k and use two pointers to check if it works\n\nTC : O(n^2)\nSC : O(n)\n\nclass Solution {\npublic:\n | bcb98801xx | NORMAL | 2022-10-20T11:14:30.313022+00:00 | 2022-10-20T11:14:52.694081+00:00 | 43 | false | 1. find all possible `k`\n2. sort `nums`\n3. iterate all possible `k` and use two pointers to check if it works\n\nTC : O(n^2)\nSC : O(n)\n```\nclass Solution {\npublic:\n vector<int> recoverArray(vector<int>& nums) {\n int n = nums.size();\n\t\t// find all possible k\n unordered_set<long> ks;\n ... | 0 | 0 | [] | 0 |
recover-the-original-array | [Python] Greedy || Hashmap || Priority Queue | python-greedy-hashmap-priority-queue-by-f442j | \nclass Solution:\n def recoverArray(self, nums: List[int]) -> List[int]:\n heapify(nums)\n n0, h0 = len(nums), Counter(nums)\n for kk i | coolguazi | NORMAL | 2022-10-14T13:28:40.425839+00:00 | 2022-10-14T13:30:25.388136+00:00 | 112 | false | ```\nclass Solution:\n def recoverArray(self, nums: List[int]) -> List[int]:\n heapify(nums)\n n0, h0 = len(nums), Counter(nums)\n for kk in map(lambda x: x - nums[0], nums):\n if kk <= 0 or kk % 2: continue\n ans, nms, n, h = [], nums[:], n0, h0.copy()\n while T... | 0 | 0 | ['Greedy', 'Heap (Priority Queue)', 'Python'] | 0 |
recover-the-original-array | rust 105ms | rust-105ms-by-drizz1e-yzcp | rust\nimpl Solution {\n pub fn recover_array(nums: Vec<i32>) -> Vec<i32> {\n use std::collections::HashMap;\n let mut nums = nums.clone();\n | drizz1e | NORMAL | 2022-10-06T14:49:56.868222+00:00 | 2022-10-06T14:49:56.868268+00:00 | 18 | false | ```rust\nimpl Solution {\n pub fn recover_array(nums: Vec<i32>) -> Vec<i32> {\n use std::collections::HashMap;\n let mut nums = nums.clone();\n nums.sort();\n let smallest = nums[0];\n let mut last_k = -1;\n let mut left = HashMap::new();\n for &n in &nums {\n ... | 0 | 0 | [] | 0 |
recover-the-original-array | Python Solution using HashMap | python-solution-using-hashmap-by-hemantd-mfm3 | \nclass Solution:\n def recoverArray(self, nums: List[int]) -> List[int]:\n sz = len(nums)\n nums.sort()\n for i in range(1, sz):\n | hemantdhamija | NORMAL | 2022-09-18T10:41:24.268012+00:00 | 2022-09-18T10:41:24.268058+00:00 | 64 | false | ```\nclass Solution:\n def recoverArray(self, nums: List[int]) -> List[int]:\n sz = len(nums)\n nums.sort()\n for i in range(1, sz):\n k, hashMap = nums[i] - nums[0], Counter(nums)\n if k % 2 or k == 0:\n continue\n ans, gotIt = [], True\n ... | 0 | 0 | ['Greedy', 'Python'] | 0 |
recover-the-original-array | Simple Python Solution | simple-python-solution-by-archangel1235-nlah | \nfrom collections import Counter\n\nclass Solution:\n def findOriginalArray(self, changed: List[int], target : int):\n changed.sort()\n c1,c2, | archangel1235 | NORMAL | 2022-09-15T21:03:01.820194+00:00 | 2022-09-15T21:03:41.430501+00:00 | 25 | false | ```\nfrom collections import Counter\n\nclass Solution:\n def findOriginalArray(self, changed: List[int], target : int):\n changed.sort()\n c1,c2,length = 0,0,len(changed)\n count_map = Counter(changed)\n original = []\n if length%2 :\n return original\n while (c1... | 0 | 0 | [] | 0 |
recover-the-original-array | C++ || multiset || BRUTE FORCE | c-multiset-brute-force-by-mukesh0765-cgd4 | Approach\nstep 1:- Sort the array.\nstep 2:- The smallest element will be the first element of lower array. So find every possible of values of K with respect t | mukesh0765 | NORMAL | 2022-09-15T20:33:13.268835+00:00 | 2022-09-15T20:33:13.268876+00:00 | 60 | false | ***Approach***\nstep 1:- Sort the array.\nstep 2:- The smallest element will be the first element of lower array. So find every possible of values of K with respect to the smallest element.\nstep 3:- If the total number of count is equal to the size of the array for any K then simply return the array.\n\n\n```\nclass S... | 0 | 0 | ['C'] | 0 |
recover-the-original-array | c++ | c-by-ramdayalbishnoi29-484w | \n\n"""\n\nclass Solution {\n \nprivate:\n bool solve(multisetms,vector&ans,int k){\n \n while(!ms.empty()){\n int low=ms.begin();\n | ramdayalbishnoi29 | NORMAL | 2022-09-15T18:14:07.514787+00:00 | 2022-09-15T18:14:07.514830+00:00 | 21 | false | \n\n"""\n\nclass Solution {\n \nprivate:\n bool solve(multiset<int>ms,vector<int>&ans,int k){\n \n while(!ms.empty()){\n int low=*ms.begin();\n int high=low+2*k;\n \n if(ms.find(high)==ms.end())return false;\n \n ans.push_back(low+k);\n \n ... | 0 | 0 | [] | 0 |
recover-the-original-array | C++ || O(N^2) || EASY APPROACH EXPLAINED || HASHMAP | c-on2-easy-approach-explained-hashmap-by-s2rg | This solution is next level of question : https://leetcode.com/problems/find-original-array-from-doubled-array/\n\nLets say we have any arbitary value for K ,\n | sumitChoube238 | NORMAL | 2022-09-15T15:39:07.122976+00:00 | 2022-09-15T15:40:24.830427+00:00 | 56 | false | This solution is next level of question : https://leetcode.com/problems/find-original-array-from-doubled-array/\n\nLets say we have any arbitary value for K ,\n* We will first sort the array and store frequency all the element in a map ;\n* We will go by each element and check if that nums[i] and nums[i] +k*2 is pres... | 0 | 0 | [] | 0 |
recover-the-original-array | ✔️ Clean and well structured Python3 implementation (Top 93.2%) || Very simple | clean-and-well-structured-python3-implem-z662 | I found this Github repository with solutions to Leetcode problems https://github.com/AnasImloul/Leetcode-solutions\nThe ability to find every solution in one l | Kagoot | NORMAL | 2022-08-27T19:05:39.558045+00:00 | 2022-08-27T19:05:39.558081+00:00 | 92 | false | I found this Github repository with solutions to Leetcode problems https://github.com/AnasImloul/Leetcode-solutions\nThe ability to find every solution in one location is very helpful, I hope it helps you too\n```\nclass Solution(object):\n def recoverArray(self, nums):\n nums.sort()\n mid = len(nums) ... | 0 | 0 | ['Python3'] | 0 |
recover-the-original-array | Simple python solution | simple-python-solution-by-xiemian-jun1 | ```\nclass Solution:\n def recoverArray(self, nums: List[int]) -> List[int]:\n nums.sort()\n \n dis = list(set([nums[i] - nums[0] for i | xiemian | NORMAL | 2022-08-01T03:25:16.736063+00:00 | 2022-08-01T03:25:16.736104+00:00 | 34 | false | ```\nclass Solution:\n def recoverArray(self, nums: List[int]) -> List[int]:\n nums.sort()\n \n dis = list(set([nums[i] - nums[0] for i in range(1, len(nums) // 2 + 1) if (nums[i] - nums[0]) % 2 == 0]))\n rec = OrderedDict()\n pos = defaultdict(deque)\n\n res = []\n \... | 0 | 0 | [] | 0 |
recover-the-original-array | [Java] try all possible k | java-try-all-possible-k-by-aybx96-0jtj | \n public int[] recoverArray(int[] nums) {\n var count = new HashMap<Integer, Integer>();\n int max = 0;\n for (int a : nums) {\n | aybx96 | NORMAL | 2022-07-09T14:27:49.019520+00:00 | 2022-07-09T14:27:49.019546+00:00 | 40 | false | ```\n public int[] recoverArray(int[] nums) {\n var count = new HashMap<Integer, Integer>();\n int max = 0;\n for (int a : nums) {\n max = Math.max(max, a);\n count.put(a, count.getOrDefault(a, 0) + 1);\n }\n var uniques = new ArrayList<Integer>(count.keySet())... | 0 | 0 | [] | 0 |
recover-the-original-array | python soln | python-soln-by-kumarambuj-2ht9 | \nclass Solution:\n def recoverArray(self, nums: List[int]) -> List[int]:\n \n \n \n nums.sort()\n n=len(nums)\n if | kumarambuj | NORMAL | 2022-06-10T06:10:23.576414+00:00 | 2022-06-10T06:10:23.576447+00:00 | 106 | false | ```\nclass Solution:\n def recoverArray(self, nums: List[int]) -> List[int]:\n \n \n \n nums.sort()\n n=len(nums)\n if n==2:\n return [(nums[0]+nums[-1])//2]\n hash={}\n \n for x in nums:\n if x not in hash:\n hash[x]... | 0 | 0 | ['Python'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.