Continuous Subarrays | Leetcode 2762

Continuous Subarrays | Leetcode 2762

Techdose

54 года назад

7,600 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@BigStin-0
@BigStin-0 - 14.12.2024 06:01

God damn, my head hurts hahaha

Ответить
@SzrIsTaken786
@SzrIsTaken786 - 14.12.2024 06:29

Had the sliding window part down, the maximum and minimum threw me off a bit but the formula is the part where I'm thinking "how the heck??"

Ответить
@vishalgadade1585
@vishalgadade1585 - 14.12.2024 07:22

As you are moving pointer again to left when we found any fault
Isn't it is disturbing cpu cycle? Because it is making knot of pointers during computation
Can we optimize this knot ?

Ответить
@eliomorningstar7392
@eliomorningstar7392 - 14.12.2024 08:11

sir is it possible if you can explain the segment or fenwick tree approach for this problem?

Ответить
@gireeswar18
@gireeswar18 - 14.12.2024 08:16

Nice explanation, may I know which blackboard you are using?

Ответить
@MP-ny3ep
@MP-ny3ep - 14.12.2024 08:21

Very beautifully explained !

Ответить
@sivapradeep977
@sivapradeep977 - 14.12.2024 08:27

Suddenly my brain is not braining😂😂

Ответить
@AlbinSabu-y2v
@AlbinSabu-y2v - 14.12.2024 08:47

This is first time I see the window is going like a swing. That made me confusing(especially the double count & subtracton🥲). If I had never seen this algo my dumb brain could never figure out the soln.

Ответить
@dieformusic1705
@dieformusic1705 - 14.12.2024 08:53

sir can i use priority queues to maintain min and max values so as to avoid the left movement of L pointer where i can update L pointer to the index choosen from the priority queues after checking the condition?

Ответить
@nileshbhanot2776
@nileshbhanot2776 - 14.12.2024 08:56

Your python does not submit on leetcode and provides wrong output. Kindly, please check

Ответить
@thetruebluesingaporeankid
@thetruebluesingaporeankid - 14.12.2024 10:01

could explain why the n*(n+1)/2 come about?

Ответить
@B-Billy
@B-Billy - 14.12.2024 10:01

I was with you until you start talking about moving L pointer.

Ответить
@Abhishek-e6d2c
@Abhishek-e6d2c - 14.12.2024 10:10

what an explanation!!!

Ответить
@vikasvoruganti7490
@vikasvoruganti7490 - 14.12.2024 10:16

Time to practice more sliding window problems 😢

Ответить
@lakithakare7387
@lakithakare7387 - 14.12.2024 10:38

Thank you

Ответить
@algorithmsanddatastructure3701
@algorithmsanddatastructure3701 - 14.12.2024 11:17

i think we can adjust the left pointer also simply by maintaining the index and updating the index if the same number occuring multiple times

Ответить
@rutikbhanushali957
@rutikbhanushali957 - 14.12.2024 11:50

Moving left pointer back to avoid duplicate was a bit tricky...

Ответить
@pravyn350
@pravyn350 - 14.12.2024 12:40

This guy ❤

Ответить
@Anikait-h3d
@Anikait-h3d - 14.12.2024 13:40

Loving the explanation Hating the problem

Ответить
@firstyfirst
@firstyfirst - 14.12.2024 13:47

would maintaining a index whenever I update max help last wala update will be stored and my next L would be ind+1;

Ответить
@jaatharsh
@jaatharsh - 14.12.2024 16:01

good explanation as always, many thanks

Ответить
@vidhyarthisunav
@vidhyarthisunav - 14.12.2024 16:28

Your Python code in the link need minor enhancement. n = len(nums) should be used instead of right pointer to calculate the final number of subarrays to be addes outside the loop on line number 126. It should be win_size = n - left instead of win_size = right - left.

Ответить
@nicolaswolyniec1354
@nicolaswolyniec1354 - 14.12.2024 17:51

the python solution will give you a wrong answer. After finishing the loop, you can not use the right variable because the value is n-1
win_size = len(nums) - left
count += (win_size * (win_size + 1)) // 2

Ответить
@AKProductionsTelugu
@AKProductionsTelugu - 14.12.2024 18:00

why don't you move the left pointer to right man its striaght forward and less complicated for explaining!

Ответить
@asgarantony
@asgarantony - 14.12.2024 18:01

Good explanation Sir.

Ответить
@sailendrachettri8521
@sailendrachettri8521 - 14.12.2024 18:22

And i was just counting subarrays

Ответить
@ujjwal_7531
@ujjwal_7531 - 14.12.2024 19:38

wonderful explain

Ответить
@freecourseplatformenglish2829
@freecourseplatformenglish2829 - 14.12.2024 20:04

Excellent expalination, I too comeup with the exact approach but struggle to code it. Thanks man.

Ответить
@LinhHoang-ml1qo
@LinhHoang-ml1qo - 14.12.2024 21:32

Hi sir, I think exactly the time complexity is O(2N) in the worst case l and r is both come to the last of index. Please confirm if my comment is false.Thank you so much and have a good day

Ответить
@smitshah2113
@smitshah2113 - 14.12.2024 21:47

Nice explanation. Thanks. Just one tiny bug: when moving back left, we need to ensure we are not moving out of the array

Ответить
@devmahad
@devmahad - 14.12.2024 22:25

thanks :)

Ответить
@ishanbhatt6067
@ishanbhatt6067 - 15.12.2024 02:12

great call to include the complexity analysis! i came up with a similar solution but rejected it because i thought moving left pointer back would cause the complexity to become N-squared!
thanks :)

Ответить
@aryan51coder
@aryan51coder - 17.12.2024 05:43

using deque makes it o(n) both time and space

Ответить