Given an array, return true if it can be partitioned into two subarrays whose sum of elements are the 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
2y
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...
Housing.com Software Developer interview questions & answers
A Software Developer was asked 5mo agoQ. Given a rotated sorted array, how can you search for a target value efficiently ...read more
A Software Developer was asked Q. Given a sorted array that has been rotated by some number of positions, find the...read more
A Software Developer was asked Q. How would you add two integers that cannot be stored even in a long long int?
Popular interview questions of Software Developer
A Software Developer was asked 5mo agoQ1. Given a rotated sorted array, how can you search for a target value efficiently ...read more
A Software Developer was asked Q2. Given a sorted array that has been rotated by some number of positions, find the...read more
A Software Developer was asked Q3. How would you add two integers that cannot be stored even in a long long int?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

