Ctrl K

Pair Each Number With Its Double

Medium
You are given an integer array values of even length. Can its elements be reordered so that they split into adjacent pairs where the second number is exactly twice the first? Formally, values[2i + 1] == 2 · values[2i] must hold for every 0 ≤ i < len(values) / 2. Return True if such an order exists, and False otherwise.
Example 1
values=[6, -2, 3, -4] → True

Pairs (3, 6) and (-2, -4), for example in the order [3, 6, -2, -4].

Example 2
values=[1, 2, 2, 8] → False

8 would need a 4 or a 16, and neither is present.

Example 3
values=[0, 5, 0, 10] → True
Constraints
  • 2 ≤ len(values) ≤ 10⁵
  • len(values) is even
  • -10⁵ ≤ values[i] ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsJobs With a Cooldown MediumDeal Into Consecutive Sets MediumSpread Out the Labels MediumPick Within Tag Limits MediumSplit Into Straight Runs Medium
loading Python…
Input
values=[6, -2, 3, -4]
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 115 tests on the server, hidden ones included.