Given an integer array of even length arr, return true if it is possible to reorder arr such that arr[2 * i + 1] = 2 * arr[2 * i] for every 0 &lt;= i &lt; len(arr) / 2, or false otherwise.

&nbsp;
Example 1:

Input: arr = [3,1,3,6]
Output: false


Example 2:

Input: arr = [2,1,2,6]
Output: false


Example 3:

Input: arr = [4,-2,2,-4]
Output: true
Explanation: We can take two groups, [-2,-4] and [2,4] to form [-2,-4,2,4] or [2,4,-2,-4].


&nbsp;
Constraints:


	2 &lt;= arr.length &lt;= 3 * 104
	arr.length is even.
	-105 &lt;= arr[i] &lt;= 105


class Solution:
    def canReorderDoubled(self, arr: List[int]) -> bool:
        n = len(arr)
        arr.sort()
        times = n//2
        count = {}
        for i in arr :
            if i in count:count[i] += 1
            else: count[i] = 1
        for i in count:
            if i == 0:
                tmp = count[0]//2
                times -= tmp
                if times <=0 : return True
            else:
                if i*2 in count:
                    ct1 = count[i]
                    ct2 = count[i*2]
                    while ct1 > 0 and ct2 > 0 and times > 0:
                        ct1 -= 1
                        ct2 -= 1
                        times -= 1
                    count[i] = ct1
                    count[i*2] = ct2
                    if times == 0:return True
        return False
class Solution {
    public boolean canReorderDoubled(int[] arr) {
        Map<Integer,Integer> map=new HashMap<>();
        int zeroCount=0,out=0,len=arr.length;
        Arrays.sort(arr);
        for(int ar:arr){
           if(ar%2==1)
               map.put(ar,map.getOrDefault(ar,0)+1);
           else
           {
               if(ar>0)
               {
                   int val=map.getOrDefault(ar/2,0);
                   if(val>0){
                       out++;
                       map.put(ar/2,val-1);
                   }
                   else map.put(ar,map.getOrDefault(ar,0)+1);
               }
               else if(ar<0)
               {
                  int val=map.getOrDefault(ar2,0);
                   if(val>0){
                       out++;
                       map.put(ar2,val-1);
                   } 
                   else map.put(ar,map.getOrDefault(ar,0)+1);
               }
               else zeroCount++;   
           }
        }
        zeroCount=zeroCount/2;
        return out+zeroCount==len/2;
    }
}
class Solution {
public:
    bool func(vector<int> pos){
        map<int,int> mp;
        for(int i=0;i<pos.size();i++){
            mp[pos[i]]++;
        }

        for(auto it:mp){
            if(mp.find(2*it.first)==mp.end()){
                return false;
            }
            if(mp[it.first]>mp[2*it.first]){
                return false;
            }
            mp[2*it.first]-=mp[it.first];
            if(mp[2*it.first]==0)
                mp.erase(2*it.first);
        }

        return true;
    }

    bool canReorderDoubled(vector<int>& arr) {
        int n=arr.size();
        vector<int> pos,neg;
        int zeroes=0;
        for(int i:arr){
            if(i>0){
                pos.push_back(i);
            }else if(i<0){
                neg.push_back(i);
            }else{
                zeroes++;
            }
        }

        if(zeroes%2!=0){
            return false;
        }

        if(neg.size()%2!=0 or pos.size()%2!=0){
            return false;
        }

        for(int i=0;i<neg.size();i++){
            neg[i]=-1*neg[i];
        }

        sort(pos.begin(),pos.end());
        sort(neg.begin(),neg.end());
        return func(pos) and func(neg);
    }
};
var canReorderDoubled = function(arr) {
    const obj = {}
    let total = 0
    arr.sort((a,b) => a-b)
    for (let i = 0; i < arr.length; i++) {
        const num = arr[i]
        if (obj[num / 2]) {
            obj[num / 2]--
            total++
        } else if (obj[num * 2]) {
            obj[num * 2]--
            total++
        } else if (obj[num]) {
            obj[num]++
        } else {
            obj[num] = 1
        }
    }

    return total >= arr.length / 2
};
Array of Doubled Pairs