Ctrl K

Repeated Neighbor Sum

Easy
A sensor logged its readings in the array readings. Add up every two adjacent readings: readings[0] + readings[1], readings[1] + readings[2], and so on. Return True if any of these sums shows up twice, meaning there are two adjacent pairs starting at different positions with the same sum. The pairs are allowed to overlap. Otherwise return False.
Example 1
readings=[3, 7, 1, 9] → True

The neighbor sums are 10, 8 and 10: the pairs (3, 7) and (1, 9) sit in different places but share a sum.

Example 2
readings=[2, 4, 6, 8] → False

The sums are 6, 10 and 14, all different.

Example 3
readings=[-5, 5, -5] → True

The pairs (-5, 5) and (5, -5) overlap, yet they start at different positions and both sum to 0.

Constraints
  • 2 ≤ len(readings) ≤ 1000
  • -10⁹ ≤ readings[i] ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPair With a Target Sum EasyThe Candidate With Most Votes EasyDoes Any Value Repeat EasyRepeat Within Reach EasyThe Lost Ticket Easy
loading Python…
Input
readings=[3, 7, 1, 9]
Expected
True

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