Imagine Alice had an array of n positive integers. She performed a clever transformation: she picked a positive integer k and created two new arrays by subtracting k from each element (creating the lower array) and adding k to each element (creating the higher array).
Here's the twist: Alice accidentally mixed all the numbers from both arrays together and lost track of the original array! ๐ค
Your mission: Given an array nums containing 2n integers (where exactly n came from the lower array and n came from the higher array), reconstruct Alice's original array.
Example: If the original array was [5, 10, 15] with k=2, Alice would create:
- Lower:
[3, 8, 13](subtract 2 from each) - Higher:
[7, 12, 17](add 2 to each) - Mixed:
[3, 7, 8, 12, 13, 17](shuffled together)
From the mixed array, you need to find the original [5, 10, 15]!
Input & Output
Time & Space Complexity
O(nยฒ) possible k values, each requiring O(n) verification time
Space for frequency map and result array