Ctrl K

The Same Shift for Everyone

Easy
A shop relabelled its prices: the same integer x was added to every price in the list before (x may be negative or zero). The result is the list after: the same prices after the change, possibly in a different order. Two lists count as equal when they hold the same numbers with the same number of repeats, in any order. Return x.
Example 1
before=[12, 5, 9], after=[7, 11, 14] → 2

Adding 2 to every price gives [14, 7, 11], the same numbers as in after, just in a different order.

Example 2
before=[40, 30], after=[10, 20] → -20

Every value dropped by 20, so the answer is −20.

Example 3
before=[6], after=[6] → 0
Constraints
  • 1 ≤ len(before) = len(after) ≤ 100
  • 0 ≤ before[i], after[i] ≤ 1000
  • A suitable x is guaranteed to exist
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPair With a Target Sum EasySqueeze Repeats Out of a Sorted Array EasyDrop the Unwanted Value EasySlot on a Sorted Shelf EasyAdd One to a Digit Array Easy
loading Python…
Input
before=[12, 5, 9], after=[7, 11, 14]
Expected
2

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