Find largest subarray with equal number of 1s and 0s?
AnswerBot
1y
Find largest subarray with equal number of 1s and 0s
Use a hashmap to store the count of 1s and 0s encountered so far
If the count of 1s and 0s is equal at any point, calculate the length of subarray
Kee...read more
ujjwal Tiwary
1y
def find_largest_subarray(array):
max_length = 0
prefix_sums = {0: -1}
count = 0
for i, num in enumerate(array):
count += 1 if num == 1 else -1
if count in prefix_sums:
length = i - prefix_sums[count]...read more
Help your peers!
Add answer anonymously...
Popular interview questions of Senior Android 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