LeetCode 1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit

  Рет қаралды 1,251

Kacy Codes

Kacy Codes

Күн бұрын

Пікірлер: 8
@TheAlexanderEdwards
@TheAlexanderEdwards 2 жыл бұрын
tremendously helpful, thank you!
@walidzein1
@walidzein1 2 жыл бұрын
Thanks man!
@littlebox4328
@littlebox4328 2 жыл бұрын
you must be using your sharingan to be this good!!! Thanks man!!
@KacyCodes
@KacyCodes 2 жыл бұрын
Just trying to awaken my susanoo xD
@djslimcodes2337
@djslimcodes2337 2 жыл бұрын
Hey @Kacy Codes , how was your Amazon interview?
@atanumondal8078
@atanumondal8078 2 жыл бұрын
Hey Kacy, Plesae Please Please make LC 1950. Maximum-of-minimum-values-in-all-subarrays
@KacyCodes
@KacyCodes 2 жыл бұрын
I solved it right now, but it's pretty tough for a medium. I don't have time to make a video so I'll link my submission and try to explain the algorithm. 1. Initialize your result array with the minimum integer value. 2. Use an increasing stack to find the indexes of the previous lesser and next lesser elements for each element in the input array. Calculate the distance from the previous lesser to the next lesser, and that's what length subarray the value at the current index you're processing is a minimum value of. 3. Update the max value in your result array for that length. (Initially I tried updating all the lengths that are greater or equal to the length, but the algorithm becomes n^2 if you do that.) You'll repeat step 2 & 3 for every element in the input array. 4. This last part was tricky for me but the intuition is that it's similar to a prefix sum. Say 100 is the max value for subarray length of 2 and you have that in your result array. But also in your result array for length 1 you only have 50. Well that doesn't make sense because if 100 is the max value for subarrays of length 2, it must also be the max value for subarrays of length 1. So to finish the "prefix sum" on the result array, I loop from the end to the beginning doing result[i] = Math.max( result[i], result[i + 1] ); leetcode.com/submissions/detail/724992785/ If you have trouble at any step I would print out your result array in your code and compare it to my solution in another tab or something.
@atanumondal8078
@atanumondal8078 2 жыл бұрын
@@KacyCodes Great. I have no words to thank you😊. Will look into it.
LeetCode 2055. Plates Between Candles - O(n + q)
16:31
Kacy Codes
Рет қаралды 4,4 М.
ТЫ В ДЕТСТВЕ КОГДА ВЫПАЛ ЗУБ😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 4,5 МЛН
They Chose Kindness Over Abuse in Their Team #shorts
00:20
I migliori trucchetti di Fabiosa
Рет қаралды 12 МЛН
The Ultimate Sausage Prank! Watch Their Reactions 😂🌭 #Unexpected
00:17
La La Life Shorts
Рет қаралды 8 МЛН
K-th element of two sorted Arrays - O( log(min(n, m)) )
23:08
Kacy Codes
Рет қаралды 2,6 М.
Dynamic Programming isn't too hard. You just don't know what it is.
22:31
DecodingIntuition
Рет қаралды 197 М.
How Senior Programmers ACTUALLY Write Code
13:37
Thriving Technologist
Рет қаралды 1,6 МЛН
CTCI 4.9 BST Sequences - Java
25:33
Kacy Codes
Рет қаралды 746
5 Simple Steps for Solving Any Recursive Problem
21:03
Reducible
Рет қаралды 1,2 МЛН
The Absolute Best Intro to Monads For Software Engineers
15:12
Studying With Alex
Рет қаралды 670 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 673 М.