Find Subarrays With Equal Sum

Given a 0-indexed integer array nums, determine whether there exist two subarrays of length 2 with equal sum. The two subarrays must begin at different indices.

Return true if these subarrays exist, and false otherwise.

A subarray is a contiguous non-empty sequence of elements within an array.

Example 1
Inputnums = [4,2,4]
Outputtrue
The subarrays with elements [4, 2] and [2, 4] have the same sum of 6.
Example 2
Inputnums = [1,2,3,4,5]
Outputfalse
No two subarrays of size 2 have the same sum.

Constraints

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

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate