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

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits