Show problems as
Classic problem #2395EasyArrayHash Table

Find Subarrays With Equal Sum

Real-world version: Two Neighbouring Pairs of Equal Load
Tracked in this browser only
Read Find Subarrays With Equal Sum on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A conveyor holds readings nums.

Consider the pairs of neighbouring readings: the pair at position i is nums[i] together with nums[i + 1]. Two such pairs are different when they start at different positions, even if they hold the same readings.

Return true when two different neighbouring pairs have the same total.

Examples

Example 1

Input
nums = [14, 9, 5, 18, 6, 17]
Output
true

The neighbouring pairs total 23, 14, 23, 24 and 23, so the pair starting at position 0 and the one starting at position 2 match.

Example 2

Input
nums = [10, 20, 30, 40, 50]
Output
false

The totals are 30, 50, 70 and 90, all different.

Example 3

Input
nums = [3, 3, 3]
Output
true

Both pairs hold the same readings and so total the same, and they start at different positions, which is what makes them different pairs.

Constraints

  • 2 <= nums.length <= 1000
  • -10^9 <= nums[i] <= 10^9

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.

Python
def find_subarrays(nums: list[int]) -> bool:
Java
public boolean findSubarrays(int[] nums)