Ctrl K

The Dropped Reading

Easy
A sensor logged readings that moved by a constant step: the difference between neighbouring readings was always the same (the step may be negative or zero). In transit one reading was lost, and it was neither the first nor the last. The remaining readings, in their original order, are in the array readings. Return the lost value.
Example 1
readings=[10, 16, 19, 22] → 13

The original sequence went up by 3: 10, 13, 16, 19, 22. The value 13 was dropped.

Example 2
readings=[40, 30, 25] → 35

The step is −5: 40, 35, 30, 25. The value 35 was dropped.

Example 3
readings=[7, 7, 7] → 7

The step is zero, so the dropped value is also 7.

Constraints
  • 3 ≤ len(readings) ≤ 1000
  • 0 ≤ readings[i] ≤ 10⁵
  • readings really is a constant-step sequence with one interior element removed
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsAdd One to a Digit Array EasyThe Lost Ticket EasyCorner Stamps on a Table EasyBest Product of Three EasyThe Biggest Triangle on the Board Easy
loading Python…
Input
readings=[10, 16, 19, 22]
Expected
13

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