LeetCode 2104. Sum of Subarray Ranges

LeetCode 2104. Sum of Subarray Ranges

Kacy Codes

2 года назад

10,024 Просмотров

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


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

@aryandumyan1195
@aryandumyan1195 - 10.09.2023 13:21

Thanku bro. it helped me a lot

Ответить
@vado4003
@vado4003 - 21.06.2023 03:48

You are fucking goated

Ответить
@raunakkumar6144
@raunakkumar6144 - 08.06.2023 16:56

Nice explanation bro.

Ответить
@kunaltripathi7342
@kunaltripathi7342 - 10.05.2023 20:46

guy has really great explanation skills.

Ответить
@Jagadeeshwarreddy-tf5pc
@Jagadeeshwarreddy-tf5pc - 04.05.2023 08:00

hey!!!!!!!!! thank you so much

Ответить
@shwetaj8189
@shwetaj8189 - 30.04.2023 15:23

Liked and Subscribed!

Ответить
@shashankshekhar8186
@shashankshekhar8186 - 19.11.2022 21:30

Best explanation of this question :)

Ответить
@mohamadsalhani1520
@mohamadsalhani1520 - 24.10.2022 00:22

thank you so much u have helped me alot! it was similar to the XXLELOUCHXX problem

Ответить
@depression_plusplus6120
@depression_plusplus6120 - 18.10.2022 11:10

My sorry ass, made for arrays and solved using stacks

SMALLER_LEFT, SMALLER RIGHT
GREATER LEFT, GREATER RIGHT
💀

Ответить
@fernandoperezzabalaga5672
@fernandoperezzabalaga5672 - 22.09.2022 00:24

Kacy thanks a lot for the solution it's so simple to understand, I was wondering how did you learn also that part of java I didn't see that BiFunction so cool

Ответить
@henz103
@henz103 - 16.09.2022 07:38

Great explanation. Thanks. Subscribed.

Ответить
@jasonxu1273
@jasonxu1273 - 07.09.2022 14:20

That was some rly rly good and clear explanations, helped me so much. Thanks heaps! You have gained a new subscriber!

Ответить
@richardcheng7804
@richardcheng7804 - 05.09.2022 06:49

You gave the best explanation of this. I also loved that you didn’t create a NLE and PLE for each type of stack.

Ответить
@kahhuanyap6313
@kahhuanyap6313 - 02.09.2022 19:16

Thank you very much for the explanation!

Ответить
@kevinscaria
@kevinscaria - 24.08.2022 08:20

Kabhi computer ke bahar bhi aja bhai

Ответить
@lisaren6661
@lisaren6661 - 03.08.2022 02:12

Thank you so much for the video! Super clear! I have one question that how to handle the same values, like if we have two 4 in the array? Also, when we pop out the elements, when we use "<=", when we use "<"?

Ответить
@professionalmemer8024
@professionalmemer8024 - 29.07.2022 09:42

Damn man you are so good at explaining. Thank you for making these video!

Ответить
@eTANG0
@eTANG0 - 29.07.2022 08:49

Kacy you're a beast at explaining these leetcode problems. Prepping for my Amazon interview coming up and you make it so easy to understand these concepts :D

Ответить
@FilmerWilliam
@FilmerWilliam - 17.07.2022 00:30

Great explanation man, subscribed. I was able to understand monotonic stacks through Sum of subarray mins, but the solution I studied involved finding prevLess elements and nextLess elements for each value nums[ i ].

Through your explanation, I was able to finally understand that when you pop an element in inc/dec monotonic stacks with respect to nums[ i ], you have positions of prev/next lesser/greater elements for the first popped element: i, and the new top of the stack! Crazy

Ответить
@jeremylevitt5492
@jeremylevitt5492 - 17.07.2022 00:23

You are my savior. Thank you so much!

Ответить
@estifanosbireda1892
@estifanosbireda1892 - 13.07.2022 16:23

Thanks, helped me get the core idea behind the solution.

Ответить
@Ricardo-Gonzalez
@Ricardo-Gonzalez - 08.07.2022 04:35

I aint the brightest guy, but this makes sense to me, love it!

Ответить
@venumsingh
@venumsingh - 29.06.2022 06:41

@Kacy Thanks for great explanation. Can we use the same approach to find the number of subarrays, where (max_value - min_value) of each subarray is less than or equal to a threshold value? Appreciate any insights.

Ответить
@Rahul-pr1zr
@Rahul-pr1zr - 18.06.2022 17:07

How do you get the insight of calculating the number of sub-arrays by counting spots to the left and right and multiplying them? It seems to be counting all the possible combinations. Is there a formula to it or some material worth reading?

Ответить
@timglew5234
@timglew5234 - 09.06.2022 18:58

This was a great explanation, thank you!!! Including my python3 implementation of Kacy's solution:

class Solution:
def subArrayRanges(self, nums: List[int]) -> int:
dec_stack = []
inc_stack = []

sum = 0
for i in range(len(nums) + 1):
sum += self.pushToStack(dec_stack, nums, i, dec=True) - self.pushToStack(inc_stack, nums, i, dec=False)

return sum


def pushToStack(self, stack, nums, i, dec):
sum = 0

while stack and (i == len(nums) or self.popFromStack(stack, nums, i, dec)):
pop_i = stack.pop()
prev_i = -1 if not stack else stack[-1]

sum += (pop_i - prev_i) * (i - pop_i) * nums[pop_i]

stack.append(i)
return sum


def popFromStack(self, stack, nums, i, dec):
# Return True if we need to pop from the stack to push the next index, else return False
return (nums[stack[-1]] < nums[i] and dec) or (nums[stack[-1]] > nums[i] and not dec)

Ответить
@hivaghanbari1113
@hivaghanbari1113 - 19.05.2022 00:01

Nice!

Ответить
@togitoon
@togitoon - 15.05.2022 17:55

One of the cleanest explanations for this problem. Can you also do 1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit ?

Ответить
@ThreeLiner
@ThreeLiner - 14.05.2022 20:44

Great videos, keep it up!

Ответить
@shashankdahiya1696
@shashankdahiya1696 - 13.05.2022 02:49

I cannot resist appreciating you. You explain concepts very beautifully and patiently. : Respect++ : And write a damn clean code.

Ответить
@suandy7076
@suandy7076 - 11.05.2022 02:58

Thanks man!

Ответить
@jameshuang9410
@jameshuang9410 - 10.05.2022 19:19

nice explanation

Ответить
@ZZ-wt1xd
@ZZ-wt1xd - 09.05.2022 00:50

I like every leetcode video you made. The explanations are quite clear. Thanks!

Ответить