Sliding window technique - Inside code

  Рет қаралды 85,420

Inside code

Inside code

Күн бұрын

Пікірлер: 91
@mubasakz7651
@mubasakz7651 9 ай бұрын
Great explanation! Someone get this man an award!
@recursion.
@recursion. Ай бұрын
alright I just gave him a turing award now piss off
@biggn7441
@biggn7441 2 жыл бұрын
Your videos are impressive! Can you do all of the major technical interview patterns and the intuition behind them? Thanks 💯
@insidecode
@insidecode 2 жыл бұрын
Thanks a lot!
@shaheerzaman620
@shaheerzaman620 2 жыл бұрын
Nice video! Here is the solution for vowels # max number of vowels in a string of size k def max_vowels(s, k): vowels = ("a", "e", "i", "o", "u") maxvowels = 0 for ch in s[:k]: if ch in vowels: maxvowels += 1 total = maxvowels for i in range(len(s) - k): if s[i] in vowels: total -= 1 if s[i + k] in vowels: total += 1 maxvowels = max(maxvowels, total) return maxvowels
@insidecode
@insidecode 2 жыл бұрын
perfect! good job
@DAOXINNo15
@DAOXINNo15 2 ай бұрын
Would you say in this optimal way to be O(n) then because of how the two if statements are linear and all right?
@asunthakeded4967
@asunthakeded4967 Ай бұрын
sliding window made very very easier. Now I will be able to solve 80% of the problem related to sliding easily without thinking much and by visualizing
@chaos.n.dissonance
@chaos.n.dissonance 5 ай бұрын
Thank you. I've been struggling to wrap my mind around ChatGPT's explanation of sliding window technique for a few days now, this is so much simpler. def count_vowels_efficientcode(word:str, k:int) -> int: VOWELS = set('aeiou') max_vowels:int = 0 n:int = len(word) if n
@sameerhasan7376
@sameerhasan7376 Жыл бұрын
Beautiful explanation! Thank you! Was struggling with this for quite some time.
@ehapahmed1069
@ehapahmed1069 7 күн бұрын
your explanation is just simply brilliant ... I love it
@tankstechtutorials5721
@tankstechtutorials5721 8 ай бұрын
great video. Had fun brushing up on this algorithm. function maxNumOfVowels(s, k) { let maxNum = 0; function isVowel(c) { return /[aeiou]/.test(c) ? 1 : 0; } let leftBound = 0; let rightBound = k-1; let firstSlice = s.substring(leftBound, k); for (let index = 0; index < firstSlice.length; index++) { const element = firstSlice[index]; maxNum += isVowel(element); } let currentCount = maxNum; while (rightBound < s.length - 1) { leftBound++; rightBound++; if(isVowel(s[leftBound-1])) { currentCount -= 1; } if (isVowel(s[rightBound])) { currentCount += 1; } maxNum = Math.max(currentCount, maxNum); } return maxNum; }
@rnniloyiii9082
@rnniloyiii9082 4 ай бұрын
The name should be caterpillar 🙂
@pierrehebert9743
@pierrehebert9743 2 жыл бұрын
When you first introduced the problem, we wanted to pick out the best set of five books, not what the price of the best set was. That means we were looking for argmax rather than max. so the code would be closer to: def best_set_for_price(items, k): if len(items) max): max = offset argmax = i + 1 return argmax As a bonus, note how we never need to calculate the initial sum.
@insidecode
@insidecode 2 жыл бұрын
Thanks for your interesting answer
@Daniel_WR_Hart
@Daniel_WR_Hart 2 жыл бұрын
mind == blown
@badermuteb4552
@badermuteb4552 2 жыл бұрын
nicely done. the best tutorial ever. please continue making new vide like this, here is my solution: is it correct? def mnv(s,k): v = "aeoiu" ms =0 for i in range(k): if s[i] in v: ms +=1 max_substring = ms for i in range(len(s) - k): if s[i] in v: ms -= 1 if s[i+k] in v: ms += 1 max_substring = max(max_substring, ms) return max_substring how would you solve it?????
@sarthaksharma9322
@sarthaksharma9322 4 ай бұрын
Beautiful visualisation! and explanation of time complexities and algorithm, love the video so much!!❤
@algorithmdatastructures9244
@algorithmdatastructures9244 Жыл бұрын
Best video on this topic all over youtube. 😍
@megamehdi89
@megamehdi89 2 жыл бұрын
Please continue making videos. I love them ❤️
@insidecode
@insidecode 2 жыл бұрын
Sure! thanks a lot
@probabilitycodingisfunis1
@probabilitycodingisfunis1 2 жыл бұрын
Amazing videos, content is explained so well with impressive animations!
@insidecode
@insidecode 2 жыл бұрын
Thank you!
@ESLRepeat
@ESLRepeat 4 ай бұрын
thanks man, you explained the thing really well. I had fun taking the class
@iezioaudi22
@iezioaudi22 9 ай бұрын
this was the best explanation I have seen! THANK YOUU!
@Samad_27
@Samad_27 2 жыл бұрын
Plz make more videos no one can beat your level Absolutely Brilliant
@insidecode
@insidecode 2 жыл бұрын
Thanks!
@preminfi4887
@preminfi4887 3 ай бұрын
Great explanation! Awesome visualisation, it is easy to understand the problem and the solution.
@ysmerde2933
@ysmerde2933 Жыл бұрын
You know you are gonna learn something when the English speaker has an foreign accent ty for the tuto dude you insane
@anniamatthews6803
@anniamatthews6803 Ай бұрын
great explanation! you made this very simple
@value_investing_indonesia
@value_investing_indonesia 2 жыл бұрын
Absolute genius, please continue making videoss
@insidecode
@insidecode 2 жыл бұрын
Thanks! Sure
@codelinx
@codelinx Жыл бұрын
Great channel. Great illustrations and examples....🙋‍♂️
@rodrigoelias1987
@rodrigoelias1987 6 ай бұрын
here is a node solution for the exercise at the end of the video: import { strictEqual } from "assert"; const vowels = new Map([ ["a", "a"], ["e", "e"], ["i", "i"], ["o", "o"], ["u", "u"], ]); const isVowel = (v: string) => vowels.has(v); const countVowels = (string: string, span = 5) => { let vowelsCount = 0; let maxVowels = 0; for (let i = 0; i < string.length; i++) { if (i - span - 1 > -1) { if (isVowel(string[i - span - 1])) { vowelsCount--; } } if (isVowel(string[i])) { vowelsCount++; } if (vowelsCount > maxVowels) { maxVowels = vowelsCount; } } return maxVowels; }; const input = "bacacbefaobeacfe"; strictEqual( countVowels(input), 4, "The expected ammount of vowels was 4, got " + countVowels(input) );
@sainithyamsani4062
@sainithyamsani4062 2 жыл бұрын
keep uploading this kind of videos. your videos are awesome!!!
@insidecode
@insidecode 2 жыл бұрын
Sure! Thanks a lot
@kaushik.aryan04
@kaushik.aryan04 2 жыл бұрын
please make more videos like this on recursion medium hard questions
@momal51
@momal51 2 ай бұрын
Very nice explanation, thanks man !
@ramseykarr6870
@ramseykarr6870 2 ай бұрын
Best explanation ever!
@methylie
@methylie 2 жыл бұрын
Your lectures are good 😊.keep posting vedios
@rishabhranjan5162
@rishabhranjan5162 5 ай бұрын
I love these kind of explanations
@TechDoctorMalayalam
@TechDoctorMalayalam 8 ай бұрын
Great explanation and illustration
@paulsingh11
@paulsingh11 8 ай бұрын
Sounds like the key word to use the Sliding Window is "contiguous" when dealing with an Array?
@odell4709
@odell4709 11 ай бұрын
Made things very clear, thank you so much
@biloliddinfarkhodov3956
@biloliddinfarkhodov3956 10 ай бұрын
This is the best explanation I have ever watched. Thank you!
@internetandcomputerprobe4426
@internetandcomputerprobe4426 Ай бұрын
Really Informative
@shreyaskulkarni4805
@shreyaskulkarni4805 10 ай бұрын
Impressive Explanation ❤️
@Fabreg01
@Fabreg01 2 жыл бұрын
Great video!!. This technique can also be leveraged in rolling hash calculations. Solution to the sliding window to calculate max vowels count in a string class Solution: def maxVowels(self, s: str, k: int) -> int: if len(s) < k: return 0 total = 0 lookUpv = {'a':True, 'e':True, 'i':True, 'o':True, 'u':True} for c in s[:k]: if c in lookUpv: total += 1 maxTotal = total for i in range(len(s)-k): char_to_add = s[i+k] if char_to_add in lookUpv: total += 1 char_to_remove = s[i] if char_to_remove in lookUpv: total -= 1 maxTotal = max(maxTotal,total) return maxTotal
@insidecode
@insidecode 2 жыл бұрын
Yes, I'm planning a video on Rabin-Karp algorithm, which uses rolling hash
@insidecode
@insidecode 2 жыл бұрын
Hey, the video on Rabin-Karp is out
@Fabreg01
@Fabreg01 2 жыл бұрын
@@insidecode Great!!.Thanks
@bobbrysonn
@bobbrysonn 3 ай бұрын
Great explanation!
@probabilitycodingisfunis1
@probabilitycodingisfunis1 2 жыл бұрын
How do you make these animations?
@insidecode
@insidecode 2 жыл бұрын
I use PowerPoint
@R_SinghRajput
@R_SinghRajput 5 ай бұрын
Crazy explanation 🔥😎
@cecitorresmx
@cecitorresmx 8 ай бұрын
Your video help me a lot! Thank you
@aahringer
@aahringer Жыл бұрын
Well done, thank you for sharing!
@Syuzaki1301
@Syuzaki1301 8 ай бұрын
tried this in JS. Used some helper functions so I don't dilute the main function: // HELPER FUNCTIONS function isVowel(str) { let vowels = "aeiou"; return vowels.includes(str); } function countVowels(str) { let count = 0; for (let i = 0; i < str.length; i++) { if (isVowel(str[i])) count += 1; } return count; } // MAIN FUNCTION function maxVowels(s, k) { let total = countVowels(s.slice(0, 5)); let maxVowels = total; for (let i = 0; i < s.length - k; i++) { if (isVowel(s[i])) total -= 1; if (isVowel(s[i + k])) total += 1; if (maxVowels < total) maxVowels = total; } return maxVowels; }
@rodrigoelias1987
@rodrigoelias1987 6 ай бұрын
Nice content, dropping a like right now
@ananyieie
@ananyieie 7 ай бұрын
thankyou sir, great explanation☺
@averrows
@averrows 2 жыл бұрын
great video! what software did you use to create this video?
@insidecode
@insidecode 2 жыл бұрын
Thanks! I used PowerPoint
@Millicx
@Millicx 2 жыл бұрын
Priceless video
@GurtDovletov
@GurtDovletov 9 ай бұрын
Very good explanation woow
@noname_2108
@noname_2108 Жыл бұрын
very helpful, thanks!
@callmeitsh
@callmeitsh 6 ай бұрын
Nice man 👍 Thank u bro ♥️
@arsh2544
@arsh2544 6 ай бұрын
awesome video!
@peacepeace9462
@peacepeace9462 8 ай бұрын
i dont understand why the brute force for best_total_price has the "for i in range(len(prices)-k+1)" instead of "for i in range(len(prices)-k)". Could anyone explain this?
@tapin130505
@tapin130505 8 ай бұрын
because the last element should be included
@peacepeace9462
@peacepeace9462 8 ай бұрын
I figured out why. len(prices)-k+1 is the starting index of the last combination of the books. The calculations of brute force and sliding window have different index ranges.
@chanukachathurangawk
@chanukachathurangawk 4 ай бұрын
Thanks a lot.
@DiogoSilva-xx8nz
@DiogoSilva-xx8nz 7 ай бұрын
awesome channel
@____r72
@____r72 2 жыл бұрын
this channel is so top
@kurdi_x5842
@kurdi_x5842 2 жыл бұрын
thaankyou it is so clear
@hammadhassan9014
@hammadhassan9014 6 ай бұрын
you are genius
@charann18
@charann18 2 жыл бұрын
Just awesome!!!!
@SanjuKumar-hk8yy
@SanjuKumar-hk8yy Жыл бұрын
I like your videos because your content with animation and your hard work, love you dude❤️. But I am not gay.
@prathagautam9872
@prathagautam9872 7 ай бұрын
To the point!
@subee128
@subee128 6 ай бұрын
thanks
@devmahad
@devmahad Ай бұрын
thanks :)
@benhassineyoussef738
@benhassineyoussef738 3 ай бұрын
"the size doesnt have an impact"
@whiz-code
@whiz-code 4 ай бұрын
I have come up with a solution but it seems like brute force, and if so, someone help me optimize it: static int maxVowelsNum(String s, int k) { var list = List.of('a', 'e', 'i', 'o', 'u'); var p1 = 0; var p2 = k + 1; var max = 0; var count = 0; while (p2 < s.length()) { var chars = s.substring(p1, p2); for (var ch : chars.toCharArray()) { if (list.contains(ch)) { count++; } } max = Math.max(max, count); p1++; p2++; count = 0; } return max; } Thank you.
@ericlongteaches
@ericlongteaches 3 ай бұрын
5:03 I have no clue what you just said here
@ericlongteaches
@ericlongteaches 3 ай бұрын
what accent is this?
@ShivamKadam-bc4dn
@ShivamKadam-bc4dn Ай бұрын
2.07
@ShivamKadam-bc4dn
@ShivamKadam-bc4dn Ай бұрын
2:07
@nullptr.
@nullptr. 4 ай бұрын
Thanks
Sliding Window Technique - Algorithmic Mental Models
36:45
Ryan Schachte
Рет қаралды 363 М.
Big-O Notation - For Coding Interviews
20:38
NeetCode
Рет қаралды 518 М.
А я думаю что за звук такой знакомый? 😂😂😂
00:15
Денис Кукояка
Рет қаралды 4,7 МЛН
Do you love Blackpink?🖤🩷
00:23
Karina
Рет қаралды 21 МЛН
Turn Off the Vacum And Sit Back and Laugh 🤣
00:34
SKITSFUL
Рет қаралды 7 МЛН
Симбу закрыли дома?! 🔒 #симба #симбочка #арти
00:41
Симбочка Пимпочка
Рет қаралды 5 МЛН
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
The LeetCode Fallacy
6:08
NeetCode
Рет қаралды 576 М.
JavaScript Sliding Window Technique - Fixed Size
15:19
The Code Creative
Рет қаралды 15 М.
Heaps, heapsort, and priority queues - Inside code
19:01
Inside code
Рет қаралды 97 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 586 М.
Sliding Window Technique + 4 Questions - Algorithms
27:25
QuanticDev
Рет қаралды 125 М.
5 Simple Steps for Solving Any Recursive Problem
21:03
Reducible
Рет қаралды 1,2 МЛН
3 Types of Algorithms Every Programmer Needs to Know
13:12
ForrestKnight
Рет қаралды 501 М.
А я думаю что за звук такой знакомый? 😂😂😂
00:15
Денис Кукояка
Рет қаралды 4,7 МЛН