Contiguous Array - Leetcode 525 - Python

preview_player
Показать описание


0:00 - Read the problem
0:30 - Drawing Explanation
11:31 - Coding Explanation

leetcode 525

#neetcode #leetcode #python
Рекомендации по теме
Комментарии
Автор

What sets you apart from the other youtubers is the fact that you don't just explain the solution. You also explain why other methods don't work? why only this method works? and how exactly do we come up with this solution?
This video was an amazing explanation . Thank you for that.

MP-nyep
Автор

I would never think of this without seeing it before.

thisisnotok
Автор

How have you not won awards for your work. Been using your solutions for years now, I love you neetcode🌸

supercarpro
Автор

I signed my Apple summer internship offer letter yesterday, thanks a lot for all your help. I hope you continue doing what you do the best

chinmaywalinjkar
Автор

How are you supposed to know this without seeing it before :(

JensUwe-
Автор

I would have died trying to solve this problem using sliding window if you hadn't explained why we can't use sliding window here. Thanks a lot Neetcode.

GautamPanday-zq
Автор

What does everyone think of the new leetcode UI? Kinda annoying that they don't let you switch back to the old one anymore

NeetCodeIO
Автор

How are we supposed to come up with such a solution on our own in a coding interview, which is also time constrained. Maybe I'm just a beginner. And damn it's a medium question!

thisisanuragmusic
Автор

These problems are beautiful and set apart top-level coders from the rest. Hope one day to be able to solve this kind of problems myself.

alxolr
Автор

Very interesting approach. This is the TDLR for the comment section:
1. Maintain a count variable as you iterate through array. For each 0 subtract count by 1 and add by 1 for each 1.
2. Maintain a hash map in which you store the leftmost index for each count value and initialize it with 0: -1
3. As you iterate through the array if the current count value already exists in the hash map, update the size with curr_idx - map[curr_count] if that value is greater than the greatest size so far

BRBallin
Автор

1 ) change all 0's to -1's
2 ) now the question changes to finding the longest length subarray whose sum is 0

k.k.harjeeth
Автор

What a genuine mind, what a talent to explain far-not intuitive concepts in a clear, easy to grasp manner!!

Ftur--fetr
Автор

Hi Navdeep, thank you for your solution! It will be extremely helpful if you include the brainstorming notes too in the future videos. Thanks!

apoorvakhuspe
Автор

This is a very smart solution, I came up with a prefix sum solution which was basically convoluted O(N^2) solution

dpjl
Автор

Great solution as usual. 🔥

But, hope the following might make it less complex:
In simple terms, in the array, if you see
1 -> preSum - 1
0 -> preSum + 1

Then, you just have to check two cases -
1. If the preSum is 0 (equal number of 1s and 0s till that index) -> update result index
2. If the preSum already exists -> check the difference - NOTE: Should not update the hashmap (we only want the first seen preSum to stay to maximise the result)
If not both, we are seeing this preSum for the first time -> Add it to hashmap

rthnrj
Автор

leetcode- Replace Question Marks in String to Minimize Its Value. Solve this question in python in easiest way.

anirbanhossen
Автор

I don’t think I could have come up with this solution myself — and I’ll probably forget it in 20 minutes too! 😬

ankit_
Автор

This is so intelligent and I still can’t figure out how can you come up with this solution XD

huyennguyenmaingoc
Автор

Just find the prefixSum arr, add 1 if 1 or -1 if 0 or vice versa, use hashMap to compare prev values but don't store when the sum repeats otherwise it will overwrite, check the sum=0 case also

anirbandas
Автор

Finally an explanation I understood perfectly. Thanks!

mfandrade
welcome to shbcf.ru