#954

Array of Doubled Pairs

expert · 1020 · lc medium +32 · verified · 39.7% accepted · 1,571 likes · top 19%

Description

Given an even-length integer array arr, check whether the elements can be rearranged into pairs where each pair's second value is exactly double the first. Return true if such a complete pairing exists, false otherwise.

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].

Code

1
2
3