Wrong Answer on Test Case

interview-questions
amazon
programming
Tags: #<Tag:0x00007f24286788d0> #<Tag:0x00007f2428678790> #<Tag:0x00007f2428678650>

#1

Why is the Answer for this Given 13, length of Longest Subarray should be 22, i.e the whole array since no. of 1’s are 14 and no. of 0’s are 8.

A : [ 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1 ]

But the answer is given as 13. why?


#2

Question says to find " longest subarray having count of 1’s one more than count of 0’s."
Focus on “one more” here. We need countOfOnes - countOfZeros = 1.
hope that helps