Master the Fast & Slow Pointer Coding Pattern for FAANG Interviews! Boost Your Coding Skills

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ม.ค. 2025

ความคิดเห็น • 30

  • @sineadward5225
    @sineadward5225 ปีที่แล้ว +1

    Hey! Great work! I hope the grind has paid off for you.

    • @DestinationFAANG
      @DestinationFAANG  ปีที่แล้ว

      Yes, it keeps on giving. But grind never stops.

  • @MyCodingDiary
    @MyCodingDiary ปีที่แล้ว

    Your videos always make me smile, thank you for brightening my day!

  • @rishirajsingh5617
    @rishirajsingh5617 หลายเดือนก่อน

    i have a question fast and slow pointer both should start from index 0 or fast pointer should be at index 1 at starting?

    • @DestinationFAANG
      @DestinationFAANG  หลายเดือนก่อน

      Both should start at the same time

    • @mrmadhan8557
      @mrmadhan8557 28 วันที่ผ่านมา

      Fast pointer should start at index one . because in the while loop we are checking . run the while loop until slow and fast pointer are not equal (while (slow !== fast)) so if both start at the same place i.e 0 . the while loop will not execute

    • @rishirajsingh5617
      @rishirajsingh5617 27 วันที่ผ่านมา

      @@mrmadhan8557 thanks now I got it

  • @labhamjain3915
    @labhamjain3915 ปีที่แล้ว

    Nice video understood all concepts. Subbed :)

    • @DestinationFAANG
      @DestinationFAANG  ปีที่แล้ว

      Glad to hear it! Let me know if there is anything you feel I can improve upon.

  • @kashikasinghal3250
    @kashikasinghal3250 5 หลายเดือนก่อน

    Thank you for the amazing explanation sir. I just changed the sequence of code for the HappyNumber problem in the getNext method and the runtime decreased to 0ms.
    public int getNext(int n){
    int totalsum=0;
    while(n>0){
    int d=n%10;
    totalsum= totalsum+ d*d;
    n=n/10;
    }return totalsum;
    } earlier as you explained , n/=10; was before totalsum calculation still the runtime was 1ms.

  • @saadsohail8204
    @saadsohail8204 6 หลายเดือนก่อน

    Hello, amazing video. Can you explain why the time complexity of cycle in linked list would be O(n). We know that if there's a cycle they will meet at some point, but that could take a lot of time in some cases, no? Thank you.

    • @DestinationFAANG
      @DestinationFAANG  6 หลายเดือนก่อน

      Still it would be directly related to number of inputs in a linear relationship. Hence TC would be O(N)

  • @mukeshsinghdance7332
    @mukeshsinghdance7332 10 หลายเดือนก่อน

    Great work

  • @KarthikKumaresan-k1o
    @KarthikKumaresan-k1o ปีที่แล้ว

    In the last two pointer problem(happy number), how do we know when to exit the sequence creation and get to the two pointer check for loop?

    • @DestinationFAANG
      @DestinationFAANG  ปีที่แล้ว

      In the context of a two-pointer problem like the Happy Number problem, the key is to understand when to exit the sequence creation and move to the two-pointer check. The idea behind the two-pointer technique is to use two different pointers (usually iterating at different speeds) to detect a cycle in a sequence.
      In the Happy Number problem, you're generating a sequence of numbers by replacing a number with the sum of the squares of its digits. The process repeats with the new number. The two-pointer technique is particularly useful here for detecting if this sequence enters a cycle, which would mean the number is not a happy number.
      Here's how you would apply this technique:
      Fast and Slow Pointers: Start with two pointers, slow and fast. Initially, both point to the original number. Then, move slow by one step (i.e., calculate the sum of the squares of its digits once) and fast by two steps (i.e., do this process twice).
      Cycle Detection: If at any point, the fast pointer equals the slow pointer, a cycle has been detected. There are two possibilities here:
      If they meet at 1, then the number is a happy number.
      If they meet at any other number, the number is not a happy number.
      Exit Condition: The loop should continue as long as slow does not equal fast. As soon as they meet, you can exit the loop and determine whether the number is happy based on the value where they meet.
      This method is efficient for detecting cycles in sequences and is a popular approach in problems that involve repeated operations leading to potential loops.

  • @saikiran2831
    @saikiran2831 ปีที่แล้ว

    Thank you so much sir ❤ subbed❤

  • @tgtg-ud7ch
    @tgtg-ud7ch ปีที่แล้ว

    i have one question in happy number what if we run in infinite search where fastRunner != slowRunner

    • @DestinationFAANG
      @DestinationFAANG  ปีที่แล้ว

      Infinite search is never always good idea, not sustainable solution I guess. But I have to see the question to really understand what are you talking about. I don't remember the question TBH

  • @happyVibesOnly1618
    @happyVibesOnly1618 13 วันที่ผ่านมา

    Happy number is Supposed to be medium problem

  • @tgtg-ud7ch
    @tgtg-ud7ch ปีที่แล้ว

    Thank you

  • @iatomic_1
    @iatomic_1 9 หลายเดือนก่อน

    The number of subs u have isnt fair 😭

    • @DestinationFAANG
      @DestinationFAANG  9 หลายเดือนก่อน

      Hopefully they will increase. Till then I will keep on trying. Thanks

  • @depression_plusplus6120
    @depression_plusplus6120 ปีที่แล้ว

    The flash🤣