If there is confusion on why count "0" is initialised with -1 index, this is because before we start, we start with count of 0. If we get lets say [0,1], then it would go to -1 and 0. And as we have initialised first index of 0 as -1. And length would be -1 to 1(current index when count reached 0).
i feel that this solution was hard to come up with without already seeing some kind of pattern of this question before. When I saw the solution, I understood it, but I'm wondering if these types of questions will get intuitive with more practice? Is this considered DP?
I've got the same problem. Basically, many solutions to medium+ problems are not really trivial or intuitive as they usually are based on some external assumption or characteristic of data. I think it's almost impossible to get it right every time, but definitely, it's possible to develop some kind of intuition as there is a finite amount of categories these problems belong to. Stay cool and positive! Cheers
@@extravaganza69 yeah i think finite amount of categories you mentioned should be documented somewhere. It would be helpful to look at initially when we get stuck !!! Agree, should stay cool. Revisit the problems every interval to keep hang of it.
Hey Nick, great video. Thanks for all of your hard work. Just have a minor suggestion. I have seen a bunch of your videos and you almost tend to size the problem by saying "oh this is an easy problem" or "this problem is super simple". This might discourage the viewer into thinking they can't even solve these easy problem. And believe me, most viewers who are watching your videos are the folks who could not solve this problem and hence are looking to understand the solution. I'd appreciate if you could stop doing that. Let me know if I am being too sensitive. Again, I am your youtube subscriber and thank you!
Think about a simple condition where your array is [0,1] this would not update maxlen when the count becomes 0. Adding this check gives you (index - (-1)) so your maxlen = 2 now. Don't think about adding this condition first. Think about a test case or a counter example that breaks your logic without this condition. Adding this condition would appear natural at that point.
Thanks for clearing the problem and going over the solution. I was having a hard time understanding the concept of `contiguous` (non-native english speaker), and the longer example plus your code helped a lot.
initially thought of this problem as max contiguous subarray equals k, where k = 0 and all 0s are converted into -1, hope that helps anyone thinking through this problem
I don't understand the example, why is [0,1] maxlen is 2, and [0,1,0] maxlen is still 2, I had a look at the discussion and get more confused... I hope someone can explain this properly before I can formulate a logic to solve this. [0,0,0,1,1,2,1] = 6 // other numbers than 0 and 1 are ignored [0,1,0,1] = 4 // so this is 4, why? [0,1,0,1,1] = 4 // this is also 4... so there is some symetry condition?? [0,0,1,0,0,0,1,1] = 6 // this is 6?? I do not see why. I would have expected 4
i have the same confusion bruh . this bastard in this video explain shit . he always rush up never cares about the viewers understanding worst experience.
took a a lot of re-read the problem statement to clear up my confusion, to answer you: [0,0,0,1,1,2,1] i believe you meant [0,0,0,1,1,0,1] , it is 6 because starting from the 2nd index [0,0,1,1,0,1] it is contiguous because this subarray has exactly the same number of 0 as to 1, 3 each. [0,1,0,1] = 4 because the whole array has same number of 0s and 1s, so the length of the array (4) is the longest subarray [0,1,0,1,1] = 4 because up to the first 4 elements, the subarray has exactly the same number of 0s and 1s, therefore it is 4. [0,0,1,0,0,0,1,1] = 6, from the 3rd index to the end, it has the same number of 0s and 1s therefore it is 6.
@@damudaran3765 instead of blaming others of not explaining in the level of detail that you are expecting, you could be more helpful by explaining what exactly you are confused with and ask for help around that confusion. you need to help others to understand what you don't for others to help you. your comment come across to me that you have spent no effort of trying to understand your own confusion.
Nick : "It's not that hard, it could be easy even."
Also Nick Submissions : Multiple Rejection
Cmon dude...
lmfao
hahaha
It is definitely a medium problem. counts.put(0, -1) only this line could kill 90% people if they have never study this problem before.
Totally!!
yaaay! only (0,-1) part makes it hard
Or JUST PUT
for(let i = 0; i
@@valiibraimi195 bro thanks
If there is confusion on why count "0" is initialised with -1 index, this is because before we start, we start with count of 0. If we get lets say [0,1], then it would go to -1 and 0. And as we have initialised first index of 0 as -1. And length would be -1 to 1(current index when count reached 0).
Got it now! Thanks!
i feel that this solution was hard to come up with without already seeing some kind of pattern of this question before. When I saw the solution, I understood it, but I'm wondering if these types of questions will get intuitive with more practice? Is this considered DP?
I've got the same problem. Basically, many solutions to medium+ problems are not really trivial or intuitive as they usually are based on some external assumption or characteristic of data. I think it's almost impossible to get it right every time, but definitely, it's possible to develop some kind of intuition as there is a finite amount of categories these problems belong to. Stay cool and positive! Cheers
@@extravaganza69 yeah i think finite amount of categories you mentioned should be documented somewhere. It would be helpful to look at initially when we get stuck !!!
Agree, should stay cool. Revisit the problems every interval to keep hang of it.
Consider two indices i and j where i
Hey Nick, great video. Thanks for all of your hard work. Just have a minor suggestion. I have seen a bunch of your videos and you almost tend to size the problem by saying "oh this is an easy problem" or "this problem is super simple". This might discourage the viewer into thinking they can't even solve these easy problem. And believe me, most viewers who are watching your videos are the folks who could not solve this problem and hence are looking to understand the solution. I'd appreciate if you could stop doing that. Let me know if I am being too sensitive. Again, I am your youtube subscriber and thank you!
Yeah this is not easy question.
i understand that we are putting -1 for 0, coz we have not seen 0 yet. But why we are initially putting 0 inside map?
Think about a simple condition where your array is [0,1] this would not update maxlen when the count becomes 0. Adding this check gives you (index - (-1)) so your maxlen = 2 now. Don't think about adding this condition first. Think about a test case or a counter example that breaks your logic without this condition. Adding this condition would appear natural at that point.
Thanks for clearing the problem and going over the solution. I was having a hard time understanding the concept of `contiguous` (non-native english speaker), and the longer example plus your code helped a lot.
i didnt quite get the part why we added 0 in the map initially to -1. What was the intuition behind that? That was the trickiest part.
Did not really get why this video was created if the whole idea was to just read the solution from the solutions section.
Watch mine.. I think you might get help
@@AnandPandeyHere ok...going to do that
Cuz, he cares more about views. Basically he said and read the same thing on the solutions, and copy the solution code.
u r really good! how did you practice and for how long before you could code like this?
Can u plz tell why we added 0,-1 into our hashmap before going through the array didn't get that part
this is a fabulous way of looking at the problem. i wouldn't have comeup with this solution.
initially thought of this problem as max contiguous subarray equals k, where k = 0 and all 0s are converted into -1, hope that helps anyone thinking through this problem
I thought of someway of substracting the number of zeros and ones to arrive at the solution....,
Wow man, love your brains
i try many ways before view video, this is great. It is simple and power, thank you.
I don't understand the example, why is [0,1] maxlen is 2, and [0,1,0] maxlen is still 2, I had a look at the discussion and get more confused... I hope someone can explain this properly before I can formulate a logic to solve this.
[0,0,0,1,1,2,1] = 6 // other numbers than 0 and 1 are ignored
[0,1,0,1] = 4 // so this is 4, why?
[0,1,0,1,1] = 4 // this is also 4... so there is some symetry condition??
[0,0,1,0,0,0,1,1] = 6 // this is 6?? I do not see why. I would have expected 4
i have the same confusion bruh . this bastard in this video explain shit . he always rush up never cares about the viewers understanding worst experience.
took a a lot of re-read the problem statement to clear up my confusion, to answer you:
[0,0,0,1,1,2,1] i believe you meant [0,0,0,1,1,0,1] , it is 6 because starting from the 2nd index [0,0,1,1,0,1] it is contiguous because this subarray has exactly the same number of 0 as to 1, 3 each.
[0,1,0,1] = 4 because the whole array has same number of 0s and 1s, so the length of the array (4) is the longest subarray
[0,1,0,1,1] = 4 because up to the first 4 elements, the subarray has exactly the same number of 0s and 1s, therefore it is 4.
[0,0,1,0,0,0,1,1] = 6, from the 3rd index to the end, it has the same number of 0s and 1s therefore it is 6.
@@damudaran3765 instead of blaming others of not explaining in the level of detail that you are expecting, you could be more helpful by explaining what exactly you are confused with and ask for help around that confusion. you need to help others to understand what you don't for others to help you.
your comment come across to me that you have spent no effort of trying to understand your own confusion.
@@anybody_y great explanation man, I've missed something like that while going through the statement of the problem
@@anybody_y thanks for your explanation, so basically, contiguous means same count of 1 and 0? The longest contiguous same count of 1 and 0?
awesome work! helped me very much. I did not enjoy going through that animation at all lmaoo
I liked how you explained what is binary :-)
Thank you for amazing explaination
Great explanation thank you
Can we solve this using bottom up dp???
I think, without hashmap dp will not be possible in O(n) time
Thank you! Great explanation!
Thank you
Brilliant!
awesome
bruh! you are the shiznit! that is all!!!!!!
You are the best
Return No of times 0 occurs ×2
Im the 25,000 th view , 500 th like