Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Equal Sum Subarrays

Easy Acceptance 50.00% Points 20.00

Given an array of integers arr, return true if it is possible to split it in two subarrays (without reordering the elements), such that the sum of the two subarrays are equal. If it is not possible then return false.

Examples
Example 1

Example 1

Input: arr = [1, 2, 3, 4, 5, 5]

Output: true

Explanation: In the above example, we can divide the array into two subarrays with equal sum. The two subarrays are: [1, 2, 3, 4] and [5, 5]. The sum of both the subarrays are 10. Hence, the answer is true.

Example 2

Example 2

Input: arr = [4, 3, 2, 1]

Output: false

Explanation: In the above example, we cannot divide the array into two subarrays with equal sum. Hence, the answer is false.

Hints
Hint 1
NA
Constraints
  • 1<=arr.size()<=10^5
  • 1<=arr[i]<=10^6
Companies
Meta
Topics
Queue
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions