1
// Idea is to sort the input array first then start traversing the array2
// now if we saw half of the current element before and that half is unmatched then3
// match both of them otherwise note the occurence of current element inorder4
// to match it with its double element in the future6
// Time -> O(nlogn) due to sorting7
// Space -> O(n) due to map10
* @param {number[]} changed13
var findOriginalArray = function (changed) {14
const n = changed.length;15
if (n % 2 === 1) return [];20
changed.sort((a, b) => {24
for (let ele of changed) {26
if (map.has(half) && map.get(half) > 0) {28
map.set(half, map.get(half) - 1);30
map.set(ele, map.has(ele) ? map.get(ele) + 1 : 1);34
if (original.length !== n / 2) return [];