Skip to content

Muawiya-contact/partition-equal-subset-sum-dp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Partition Equal Subset Sum (LeetCode 416)

This repository contains a Python solution to the classic "Partition Equal Subset Sum" problem from LeetCode, solved using an optimized Dynamic Programming approach.

🧠 Problem Statement

Given a non-empty array nums containing only positive integers, determine if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.

Example 1

Input: nums = [1, 5, 11, 5]

Output: true

Explanation: The array can be partitioned as [1, 5, 5] and [11].

Example 2

Input: nums = [1, 2, 3, 5]

Output: false

✅ Solution Approach

  • Calculate the total sum of all elements.
  • If the sum is odd, return False (can't split into two equal subsets).
  • If even, check if there's a subset with sum = total // 2 using 1D Dynamic Programming.
  • Time Complexity: O(n * sum)
  • Space Complexity: O(sum)

🌟 Star This Repo

Feel free to star ⭐ the repo and share with others if you find this helpful.

Releases

No releases published

Packages

No packages published

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy