Given an array, return true, if it can be partitioned into two subarrays whose sum of elements are same, else return false Example: Input: {5,1,5,11} Output: true (as it can be divided into {5,1,5} {11} where 5+1+5=11)
AnswerBot
1y
Check if an array can be partitioned into two subarrays with equal sum.
Iterate through the array and calculate the total sum of all elements.
If the sum is odd, return false as it cannot be divided int...read more
Sankar Akula
1y
def can_partition(arr):
total_sum = sum(arr)
if total_sum % 2 != 0:
return False
target_sum = total_sum // 2
n = len(arr)
dp = [[False] * (target_sum + 1) for _ in range(n+1)]
for i in range(n+1):
dp[...read more
Help your peers!
Add answer anonymously...
Top Housing.com Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Housing.com Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app