Sliding window technique - Inside code

Поделиться
HTML-код
  • Опубликовано: 20 авг 2024

Комментарии • 79

  • @mubasakz7651
    @mubasakz7651 6 месяцев назад +23

    Great explanation! Someone get this man an award!

  • @biggn7441
    @biggn7441 2 года назад +18

    Your videos are impressive! Can you do all of the major technical interview patterns and the intuition behind them? Thanks 💯

  • @rnniloyiii9082
    @rnniloyiii9082 22 дня назад +10

    The name should be caterpillar 🙂

  • @shaheerzaman620
    @shaheerzaman620 2 года назад +6

    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

  • @ESLRepeat
    @ESLRepeat 29 дней назад +1

    thanks man, you explained the thing really well. I had fun taking the class

  • @chaos.n.dissonance
    @chaos.n.dissonance Месяц назад

    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

  • @megamehdi89
    @megamehdi89 2 года назад +6

    Please continue making videos. I love them ❤️

  • @Samad_27
    @Samad_27 2 года назад +7

    Plz make more videos no one can beat your level Absolutely Brilliant

  • @sameerhasan7376
    @sameerhasan7376 Год назад +5

    Beautiful explanation! Thank you! Was struggling with this for quite some time.

  • @algorithmdatastructures9244
    @algorithmdatastructures9244 10 месяцев назад +2

    Best video on this topic all over youtube. 😍

  • @badermuteb4552
    @badermuteb4552 Год назад +3

    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?????

  • @probabilitycodingisfunis1
    @probabilitycodingisfunis1 Год назад +7

    Amazing videos, content is explained so well with impressive animations!

  • @pierrehebert9743
    @pierrehebert9743 2 года назад +1

    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.

  • @sarthaksharma9322
    @sarthaksharma9322 Месяц назад

    Beautiful visualisation! and explanation of time complexities and algorithm, love the video so much!!❤

  • @ysmerde2933
    @ysmerde2933 Год назад

    You know you are gonna learn something when the English speaker has an foreign accent ty for the tuto dude you insane

  • @preminfi4887
    @preminfi4887 12 дней назад

    Great explanation! Awesome visualisation, it is easy to understand the problem and the solution.

  • @tankstechtutorials5721
    @tankstechtutorials5721 5 месяцев назад

    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;
    }

  • @iezioaudi22
    @iezioaudi22 5 месяцев назад +1

    this was the best explanation I have seen!
    THANK YOUU!

  • @value_investing_indonesia
    @value_investing_indonesia 2 года назад +1

    Absolute genius, please continue making videoss

  • @rodrigoelias1987
    @rodrigoelias1987 3 месяца назад

    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)
    );

  • @bobbrysonn
    @bobbrysonn 9 дней назад

    Great explanation!

  • @codelinx
    @codelinx 10 месяцев назад +1

    Great channel. Great illustrations and examples....🙋‍♂️

  • @rishabhranjan5162
    @rishabhranjan5162 2 месяца назад

    I love these kind of explanations

  • @sainithyamsani4062
    @sainithyamsani4062 2 года назад +1

    keep uploading this kind of videos. your videos are awesome!!!

  • @kaushik.aryan04
    @kaushik.aryan04 Год назад +1

    please make more videos like this on recursion medium hard questions

  • @Fabreg01
    @Fabreg01 2 года назад +1

    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 года назад +1

      Yes, I'm planning a video on Rabin-Karp algorithm, which uses rolling hash

    • @insidecode
      @insidecode  Год назад +1

      Hey, the video on Rabin-Karp is out

    • @Fabreg01
      @Fabreg01 Год назад

      @@insidecode Great!!.Thanks

  • @methylie
    @methylie Год назад +1

    Your lectures are good 😊.keep posting vedios

  • @paulsingh11
    @paulsingh11 5 месяцев назад

    Sounds like the key word to use the Sliding Window is "contiguous" when dealing with an Array?

  • @TechDoctorMalayalam
    @TechDoctorMalayalam 5 месяцев назад

    Great explanation and illustration

  • @odell4709
    @odell4709 8 месяцев назад

    Made things very clear, thank you so much

  • @R_SinghRajput
    @R_SinghRajput 2 месяца назад

    Crazy explanation 🔥😎

  • @shreyaskulkarni4805
    @shreyaskulkarni4805 7 месяцев назад

    Impressive Explanation ❤️

  • @cecitorresmx
    @cecitorresmx 4 месяца назад

    Your video help me a lot! Thank you

  • @Millicx
    @Millicx 2 года назад

    Priceless video

  • @aahringer
    @aahringer Год назад

    Well done, thank you for sharing!

  • @rodrigoelias1987
    @rodrigoelias1987 3 месяца назад

    Nice content, dropping a like right now

  • @Pretty-Skie
    @Pretty-Skie 4 месяца назад

    thankyou sir, great explanation☺

  • @hammadhassan9014
    @hammadhassan9014 3 месяца назад

    you are genius

  • @arsh2544
    @arsh2544 3 месяца назад

    awesome video!

  • @chanukachathurangawk
    @chanukachathurangawk Месяц назад

    Thanks a lot.

  • @biloliddinfarkhodov3956
    @biloliddinfarkhodov3956 7 месяцев назад

    This is the best explanation I have ever watched. Thank you!

  • @user-fm7qq6hy5y
    @user-fm7qq6hy5y 6 месяцев назад

    Very good explanation woow

  • @nullptr.
    @nullptr. Месяц назад

    Thanks

  • @noname_2108
    @noname_2108 Год назад

    very helpful, thanks!

  • @benhassineyoussef738
    @benhassineyoussef738 День назад

    "the size doesnt have an impact"

  • @callmeitsh
    @callmeitsh 3 месяца назад

    Nice man 👍
    Thank u bro ♥️

  • @Syuzaki1301
    @Syuzaki1301 5 месяцев назад

    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;
    }

  • @subee128
    @subee128 3 месяца назад

    thanks

  • @prathagautam9872
    @prathagautam9872 3 месяца назад

    To the point!

  • @DiogoSilva-xx8nz
    @DiogoSilva-xx8nz 4 месяца назад

    awesome channel

  • @charann18
    @charann18 2 года назад

    Just awesome!!!!

  • @____r72
    @____r72 Год назад

    this channel is so top

  • @peacepeace9462
    @peacepeace9462 5 месяцев назад

    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 5 месяцев назад

      because the last element should be included

    • @peacepeace9462
      @peacepeace9462 5 месяцев назад

      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.

  • @averrows
    @averrows 2 года назад

    great video! what software did you use to create this video?

    • @insidecode
      @insidecode  2 года назад +2

      Thanks! I used PowerPoint

  • @kurdi_x5842
    @kurdi_x5842 Год назад

    thaankyou it is so clear

  • @probabilitycodingisfunis1
    @probabilitycodingisfunis1 Год назад

    How do you make these animations?

  • @SanjuKumar-hk8yy
    @SanjuKumar-hk8yy Год назад +1

    I like your videos because your content with animation and your hard work, love you dude❤️. But I am not gay.

  • @ericlongteaches
    @ericlongteaches 18 дней назад

    5:03 I have no clue what you just said here

  • @isaacwhiz
    @isaacwhiz Месяц назад

    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.