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...
Housing.com Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter