Skip to main content
All Questions

Partition an array into two sub-arrays with equal sum.

Medium

Given an array of integers, determine if it can be partitioned into two subsets such that the sum of the elements in each subset is equal.

A partition is considered valid if it divides the array into two subsets where both subsets have the same sum.

Examples

Input: [2, 4, 11, 5] Output: True Explanation: The array can be partitioned into two subsets [2, 4, 5] and [11] with equal sum. Input: [2, 7, 3, 1] Output: False Explanation: The array cannot be partitioned into two subsets with equal sums.

Related courses

Course

Data Engineering Interview Prep

Land your dream data engineering role at Meta, Google, Amazon, Microsoft, Walmart, DoorDash, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates. Practice data modeling, pipeline design, SQL, coding, behavioral interviews, and more.

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.