Find Original Array From Doubled Array
Real-world version: Recover the Base ReadingsThe statement here is our own: the same inputs, outputs and technique.
A calibration rig measures a batch of samples. For every sample the rig prints two rows on one sheet: the sample's base reading, and a second row holding exactly twice that base reading. A base reading of 0 therefore prints two rows of 0. The sheet then went through a shredder and was reassembled in some arbitrary order, giving the list sheet.
Work out the base readings the rig measured and return them in ascending order. If no set of base readings could have printed sheet — including the case where sheet holds an odd number of rows — return an empty list.
Examples
Example 1
- Input
- sheet = [6, 3, 1, 2]
- Output
- [1, 3]
Base reading 1 printed the rows 1 and 2, and base reading 3 printed the rows 3 and 6. Together those four rows are exactly the sheet, so the base readings are reported ascending.
Example 2
- Input
- sheet = [0, 0, 3, 6]
- Output
- [0, 3]
Base reading 0 printed two rows of 0, and base reading 3 printed the rows 3 and 6.
Example 3
- Input
- sheet = [3, 3, 6, 6, 12, 12]
- Output
- []
There is no set of three base readings whose printed rows come to this sheet, so the empty list is returned.
Constraints
- 1 <= sheet.length <= 10^5
- 0 <= sheet[i] <= 10^5
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def recover_base_readings(sheet: list[int]) -> list[int]:public int[] recoverBaseReadings(int[] sheet)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Make Array Zero by Subtracting Equal AmountsReal-world version: Rounds Needed to Clear Every ReadingEasy
- Task SchedulerReal-world version: Press Die CooldownMedium
- Maximum Palindromes After OperationsReal-world version: Noticeboard Word StripsMedium
- Hand of StraightsReal-world version: Filing Journal Issues Into Display RunsMedium