Find Subarrays With Equal Sum
Real-world version: Two Neighbouring Pairs of Equal LoadThe 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.
def find_subarrays(nums: list[int]) -> bool:public boolean findSubarrays(int[] nums)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 11 test cases: 11 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's