<p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,5,11,5]
<strong>Output:</strong> true
<strong>Explanation:</strong> The array can be partitioned as [1, 5, 5] and [11].
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,2,3,5]
<strong>Output:</strong> false
<strong>Explanation:</strong> The array cannot be partitioned into equal sum subsets.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 200</code></li>
	<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
</ul>

class Solution:
    def canPartition(self, arr: List[int]) -> bool:
        tot_Sum = 0
        for i in arr:
            tot_Sum +=i
        target = tot_Sum//2
        if (tot_Sum%2!=0):
            return False
        n = len(arr)
        hm = defaultdict(bool)

        hm[(0,0)] = True
        for i in range(1,n+1):
            curr = arr[i - 1]
            for j in range(target+1):
                if j<curr:
                    hm[(i,j)] =  hm[(i-1,j)]
                else:
                    hm[(i,j)] = hm[(i-1,j)] or hm[(i-1,j-curr)]
        return hm[(n,target)]
        # def dp(i,target):
        #     if target == 0:
        #         hm[(i,target)] = True
        #         return hm[(i,target)]
        #     if i == 0:
        #         if arr[0] == target:
        #             hm[(i,target)] = True
        #             return hm[(i,target)]
        #         else:
        #             hm[i,target] = False
        #             return hm[(i,target)]
            
        #     if (i,target) in hm:
        #         return hm[(i,target)]
        #     take = False
        #     not_take = dp(i-1,target)
        #     if target>=arr[i]:
        #         take = dp(i-1,target - arr[i])
        #     hm[(i,target)] =  not_take or take
        #     return hm[(i,target)]

        # return dp(n,target)
322818