Skip to content

Practice Recover the Original Array

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2122
LeetCode Problem

Recover the Original Array

Problem Statement

nums is a shuffled combination of lower[i] = arr[i] - k and higher[i] = arr[i] + k for an unknown positive integer k and an unknown positive-integer array arr. Return any arr of half the length of nums that could generate exactly this multiset. At least one valid reconstruction exists.

Source: Recover the Original Array on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [2,10,6,4,8,12]
Output
[3,7,11]

# Example 2

Input
nums = [1,1,3,3]
Output
[2,2]

# Example 3

Input
nums = [5,435]
Output
[220]

Constraints

2 * n == nums.length
1 <= n <= 1000
1 <= nums[i] <= 10^9
The test cases are generated such that there exists at least one valid array arr.

Related LeetCode Problems

Practice more problems similar to Recover the Original Array.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.