Tap here to switch tabs
Problem
Submissions

Problem: Recover the Original Array

Try to solve the Recover the Original Array problem.

Statement

An unknown array of integers arr containing nn elements was used to construct a new array nums. A positive integer kk (k>0k > 0) was chosen, and two arrays were formed:

  • lower, where lower[i] == arr[i] −k- k for each index ii

  • higher, where higher[i] == arr[i] +k+ k for each index ii

The elements of lower and higher were then combined in an arbitrary order to form the array nums of length 2×n2 \times n.

Given the array nums, reconstruct and return the original array arr. If there are multiple valid answers, return any of them.

Note: The integer kk must be strictly positive (k>0k > 0).

Constraints:

  • 2×n=2 \times n = nums.length

  • 1≤n≤10001 \leq n \leq 1000

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • The test cases are generated such that there exists at least one valid array arr.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Recover the Original Array

Try to solve the Recover the Original Array problem.

Statement

An unknown array of integers arr containing nn elements was used to construct a new array nums. A positive integer kk (k>0k > 0) was chosen, and two arrays were formed:

  • lower, where lower[i] == arr[i] −k- k for each index ii

  • higher, where higher[i] == arr[i] +k+ k for each index ii

The elements of lower and higher were then combined in an arbitrary order to form the array nums of length 2×n2 \times n.

Given the array nums, reconstruct and return the original array arr. If there are multiple valid answers, return any of them.

Note: The integer kk must be strictly positive (k>0k > 0).

Constraints:

  • 2×n=2 \times n = nums.length

  • 1≤n≤10001 \leq n \leq 1000

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • The test cases are generated such that there exists at least one valid array arr.