Ctrl K

Two Lost, the Rest Shifted

Medium
A collection of integers sent was shipped. On the way exactly two numbers got lost, and the same integer x (possibly negative or zero) was added to each of the rest. What arrived is received. Collections are compared regardless of order: only which numbers appear and how many times matters. Return the smallest x for which this could have happened.
Example 1
sent=[7, 3, 9, 5], received=[11, 7] → 2

x = 4 turns 3 and 7 into 7 and 11; x = 2 turns 5 and 9 into 7 and 11. The smaller shift is 2.

Example 2
sent=[6, 6, 6], received=[1] → -5

Any two numbers went missing, and the remaining 6 became 1: x = -5.

Example 3
sent=[0, 10, 20, 30, 40], received=[25, 35, 45] → 5

0 and 10 were lost, and the rest moved up by 5.

Constraints
  • 3 ≤ len(sent) ≤ 200
  • len(received) == len(sent) - 2
  • 0 ≤ sent[i], received[i] ≤ 1000
  • At least one suitable x exists
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsOriginal Array From Two Shifts HardFlowerbed Beauty on a Budget HardZero-Sum Triples MediumTriple Sum Nearest the Target MediumFour Numbers to a Target Medium
loading Python…
Input
sent=[7, 3, 9, 5], received=[11, 7]
Expected
2

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