#Leetcode

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

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

  • @sanjayjoshi8807
    @sanjayjoshi8807 3 ปีที่แล้ว +18

    Life would have been easy if greedy had easy proofs: Nice explanation though !!

  • @arpitgaurav4222
    @arpitgaurav4222 ปีที่แล้ว +14

    Got deviated with the hillarious sneaky movement behind 🤣🤣🤣🤣🤣. Great Explanation

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

      was wondering if no one else saw it

    • @Manishgupta200
      @Manishgupta200 11 หลายเดือนก่อน +1

      @@kolawoleabdulrahman I see 😂😂

  • @vyankateshkulkarni4374
    @vyankateshkulkarni4374 2 ปีที่แล้ว +13

    I was struggling to understand this question from last 2 days. i've watched ur video 3-4 times and now its clear to me. thanks for such a good explanation

  • @danussh
    @danussh 3 ปีที่แล้ว +3

    Honestly the way u explained i subscried your channel😁 took more than 5 video to understand this logic Thanks

  • @Movie_clips43456
    @Movie_clips43456 9 หลายเดือนก่อน +1

    Honestly mam appka samghane ka tarika ekdam nique hai thanku mam

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

    Thank you Alisha !! This problem had become a nightmare for me. I couldn't find it's right solution. Finally your solution helped. This is such a simple solution

  • @gitanjalikumari9262
    @gitanjalikumari9262 6 หลายเดือนก่อน +2

    Thanks for easy and nice explanation 😊

  • @thapa.shivam
    @thapa.shivam 3 ปีที่แล้ว +8

    1:21 someone sneaked into your room :P
    Concept is Crystal clear, thanks

  • @paneercheeseparatha
    @paneercheeseparatha ปีที่แล้ว +2

    Salute to your dedication🙏🙏

  • @Manishgupta200
    @Manishgupta200 11 หลายเดือนก่อน +1

    Good explaination

  • @elanza48
    @elanza48 2 ปีที่แล้ว +2

    let me add a trick i.e, add the arrowed line on the given place. this will prevent unnecessary iteration once the current and further has reached the last array element. and the previous jump is considered the optimal jump state.
    for(int i = 0; i < n-1; i++){
    --> if(curr==far && far>=nums.length-1) break;
    far = Math.max(far, (i + nums[i]));

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

      This condition is only going to be true when loop counter (i) reach the end of an array. Hence, I don't think to add this condition for reducing the iteration or further calculations in loop.

  • @ChandraShekhar-by3cd
    @ChandraShekhar-by3cd 3 ปีที่แล้ว +2

    Thanks a lot for such a great explanation!! Keep posting more video on Leetcode daily challenge.

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

    Easiest and best solution among all

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

    very good solution. good explanation

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

    Aunty was so cute, tried her best not be in the frame. Thanks for awsome explanation.

  • @ksansudeen
    @ksansudeen 2 ปีที่แล้ว

    The intuition of problem at 6.20 .. great!!!!

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

    This is is the best solution for me.

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

    Thanks mam, It took me 1 day to solve

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

    Nice Explanation

  • @saketbarnawal2167
    @saketbarnawal2167 2 ปีที่แล้ว +2

    I understand the solutin after 3 to 4 dry run.

  • @721lakhvirsingh2
    @721lakhvirsingh2 ปีที่แล้ว

    thanks mam,you cleared my doubts ,i was struggling with this question

  • @nikhilsatyam4815
    @nikhilsatyam4815 2 ปีที่แล้ว

    thanks di your explanation was superb

  • @CodeBeans.i0s
    @CodeBeans.i0s 2 ปีที่แล้ว

    Thanks - for easy explanation...

  • @RaselAhmed-ix5ee
    @RaselAhmed-ix5ee 3 ปีที่แล้ว +2

    we have to break the loop if current reaches the last index , else one extra jump will be added!

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

    literally good explanation

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

    Nice explanation . Thanks👍

  • @rakshith3547
    @rakshith3547 3 ปีที่แล้ว

    Nice explanation, do upload more such videos..

  • @RajDangi-t2b
    @RajDangi-t2b 3 หลายเดือนก่อน +1

    1:20 your mother hiding herself from camera 😁😁

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

    beautiful explanation

  • @pateladarsh1463
    @pateladarsh1463 3 ปีที่แล้ว +2

    crystal clear concept thank u :)

  • @RomanReigns-tg5qm
    @RomanReigns-tg5qm 3 ปีที่แล้ว

    finally a video with good explanation..

  • @balajijr07
    @balajijr07 ปีที่แล้ว +4

    Am i the only guy for whom the code is not working?

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

      no, it doesn't pass for me

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

    pretty good explanation

  • @ShivamYadav-in2jg
    @ShivamYadav-in2jg ปีที่แล้ว

    Thanks nicely explained

  • @lakshyasharma1940
    @lakshyasharma1940 3 ปีที่แล้ว +2

    This is such an underrated solution to this problem throughout the youtube 🙏🙏

    • @adityatiwari8930
      @adityatiwari8930 2 ปีที่แล้ว

      better u ignore. at least she is trying to help and Alisha plz ignore such bull shits....

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

      @@adityatiwari8930 kya hua bhai underrated matlab kuch glt nai hai

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

      @@adityatiwari8930 Tumne misunderstand kar diya comment ko. @lakshyasharma1940 ka matlab hai ki itne ache solution ka rating kaafi kam hai youtube par.

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

    I had solved this question using graph.
    void BFS(vector adj[],vector &visited,vector &dist,int start){
    queue q;
    q.push(start);
    dist[start]=0;
    while(!q.empty()){
    int node=q.front();
    q.pop();
    visited[node]=1;
    for(auto i:adj[node]){
    if(!visited[i]){
    visited[i]=1;
    q.push(i);
    dist[i]=dist[node]+1;
    }
    }
    }
    }
    int jump(vector& nums) {
    int n=nums.size();
    if(n

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

    U got my subscribe❤

  • @rishirachamalla5885
    @rishirachamalla5885 3 ปีที่แล้ว

    Really really good ...please increase example numbers ...like if any edge cases are there and some tips

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

    just a correction u have not added condition if i > current: return -1 , which is one of the edge case..

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

    i think the intuition u gave that "current" will point to the last made optimal jump is not correct as because
    for test case [4,1,1,3,1,1,1] the current will be pointing to indexes 0,4,6 which are not the correct positions to take a jump on...although the answer of jumps will be still 2 luckily and hence it passed that test case, so could u please explain the above test case?????????/

  • @kshitijsingh9311
    @kshitijsingh9311 3 ปีที่แล้ว

    Very nice explanation mam. Thank you

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

    Mam mere last round ke interview me ye question poochha tha (6lpa)
    Maine iska response dp se diya tha greedy approach dimaag me hit nhi hui interviewer bol rha tha optimal kro but uss time ye approach hit nhi hui but koi nhi i learned now

  • @ramyasruti9874
    @ramyasruti9874 2 ปีที่แล้ว

    Thanks for the explanation. But this is failing on 44th test case in Leetcode: [1,2,3].

  • @josevieraflores8312
    @josevieraflores8312 2 ปีที่แล้ว

    really good explained

  • @RiteshSingh-yp1sm
    @RiteshSingh-yp1sm ปีที่แล้ว

    Nice One

  • @kunalkheeva
    @kunalkheeva 2 ปีที่แล้ว +3

    why did you run the loop until arr.size()-1 instead of arr.size()

    • @PIYUSH-lz1zq
      @PIYUSH-lz1zq 2 ปีที่แล้ว

      have got this ??

    • @SaadKhan-sg4wh
      @SaadKhan-sg4wh ปีที่แล้ว +2

      @@PIYUSH-lz1zq bcuz if u go through the last element, the condition if(i==curr) will satisfy and jump++ will execute so you get an extra jump than required. Do a dry run to understand better.

  • @vishalsiddha6637
    @vishalsiddha6637 2 ปีที่แล้ว

    mashallaha mashallah solution Thanks!

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

    really helpful😊

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

    easiest approach 💙💙

  • @mayankashtekar6074
    @mayankashtekar6074 2 ปีที่แล้ว

    thanks a lot for such a great explanation

  • @AlphaWomen-d2h
    @AlphaWomen-d2h 6 หลายเดือนก่อน

    The one condition is not their that is if(i >= furthest) {return -1 } bz we cannot move forward.

  • @preetyrebari7691
    @preetyrebari7691 2 ปีที่แล้ว

    such a great explanation, thanksss!

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

    why size-1?

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

      lol got it we dont want to go anywhere from last index

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

    I==current means????

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

    why do u go till

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

    why dp is not working here

  • @aniketjaiswal3876
    @aniketjaiswal3876 3 ปีที่แล้ว

    Well explained!!, :)

  • @PIYUSH-lz1zq
    @PIYUSH-lz1zq 3 ปีที่แล้ว +1

    Can you please explain what does i==current means ??? When I and curr is becoming same ??

    • @vishalgupta957
      @vishalgupta957 2 ปีที่แล้ว

      after going through all the possible cases if we have reached the last case, then we need to update maxReach and jump as well.

  • @02deepak
    @02deepak ปีที่แล้ว

    IIB respect 🙇‍♀

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

    Her video should be on the top of the search results. Really great explanation.

  • @jimsitu5511
    @jimsitu5511 3 ปีที่แล้ว

    Why i < nums.size() - 1 but not < nums.size(), why it stops two indexes before?

    • @probabilitycodingisfunis1
      @probabilitycodingisfunis1  3 ปีที่แล้ว +10

      Thank you Jim, for asking this
      In this question, it's given you can always reach the last index
      Consider the example [2,1,1,1]
      The number of jumps you need to take is only 2 here
      First jump at 0
      Second jump at 2
      So two times you go in the case (i==current) & increment jumps
      If you take i< nums.size()
      You will consider the jumps starting from the last index also
      (when i==3) you will enter in the case (i==current)and again increase jumps and make it to 3 which is wrong

  • @TejasSharma-gu8br
    @TejasSharma-gu8br ปีที่แล้ว

    nice

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

    why do we iterate only until the second last index ?can you explain this?

  • @arambh-gaur
    @arambh-gaur 4 หลายเดือนก่อน

    To anyone whose leetcode test cases are failing with the code provided in the video here is the corrected code :
    class Solution {
    public int jump(int[] nums) {
    if(nums.length == 1) {
    return 0;
    }
    int current = 0;
    int jumps = 0;
    int farthest = 0;
    for(int i = 0; i < nums.length; i++) {
    farthest = Math.max(farthest, i + nums[i]);
    if(i == current && i != nums.length - 1) {
    current = farthest;
    ++jumps;
    }
    }
    return jumps;
    }
    }

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

    why num.sum()-1,and when we have to return true or false then only it is num.size()?????

    • @SaadKhan-sg4wh
      @SaadKhan-sg4wh ปีที่แล้ว

      bcuz if u go through the last element, the condition if(i==curr) will satisfy and jump++ will execute so you get an extra jump than required. Do a dry run to understand better.

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

    can anyone explain me that why we're traversing given array till the n-2 idx?

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

      i checked with chatgpt, it said:
      I changed the loop condition from for (int i = 0; i < nums.length; i++) to for (int i = 0; i < n - 1; i++) to iterate until the second-to-last element, as you only need to consider reaching the last element as a destination.
      in other words, our aim is to reach the last element, therefore we only need to iterate till the second last element.

    • @SaadKhan-sg4wh
      @SaadKhan-sg4wh ปีที่แล้ว

      bcuz if u go through the last element, the condition if(i==curr) will satisfy and jump++ will execute so you get an extra jump than required. Do a dry run to understand better.

  • @namratadhobale7051
    @namratadhobale7051 2 ปีที่แล้ว

    just amazing

  • @abhishek_kumar1124
    @abhishek_kumar1124 2 ปีที่แล้ว

    Thanks

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

    [0 , 1, 1, 1, 1] output of this is 1. But and is -1.can u help me to solve this issue.

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

      if u get 0 jumps at initial then there is no chance to jump to next step so u can write this edge case if(nums[0]==0)return 0

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

    mummy rocks!!!!!!

  • @reshmaparveen6679
    @reshmaparveen6679 3 ปีที่แล้ว

    Eagaely I am waiting for you ❤️❤️

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

    if the jump is not possible then we can have a check . see below.
    class Solution:
    def minJumps(self, array, n):
    if n == 0 or array[0] == 0:
    return -1
    jumps= current = farthest = 0
    for i in range(n-1):
    farthest = max(farthest, array[i] + i)
    if i >= farthest:
    return -1
    if i == current:
    current = farthest
    jumps += 1

    return jumps

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

    1:22 peeche dekho peeche 😂

    • @PIYUSH-lz1zq
      @PIYUSH-lz1zq 2 ปีที่แล้ว

      why did you run the loop until arr.size()-1 instead of arr.size()

  • @namratadhobale7051
    @namratadhobale7051 2 ปีที่แล้ว

    please take more example

  • @harshitsharma5647
    @harshitsharma5647 2 ปีที่แล้ว

    Explaination is superb but if the array elements is like
    arr = [2 1 0 3]
    then this code is not work.

    • @PIYUSH-lz1zq
      @PIYUSH-lz1zq 2 ปีที่แล้ว +1

      why did you run the loop until arr.size()-1 instead of arr.size()

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

      The question say the test cases will be such that we will reach the end.

  • @sagrikasoni7685
    @sagrikasoni7685 2 ปีที่แล้ว

    Thanku ❤️❤️

  • @namratapatil8692
    @namratapatil8692 2 ปีที่แล้ว

    Thanks for the Explanation .
    4
    2 1 0 3
    for this i/p , output is -1 but code is giving 2
    i think code will give wrong o/p if for any (a[i]+i) is giving largest index but the value of that index is 0 so our output will be -1
    how can we tackle this??

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

      You can assume that you can always reach the last index. ->REad ques carefuly

    • @Viratian_King18
      @Viratian_King18 2 ปีที่แล้ว

      int farthest=0;
      int current=0;
      int jumps=0;
      for(int i=0;i=n-1) break;
      if(current==i){
      current=farthest;
      jumps++;
      }
      }
      if (n==1) return 0;
      //cout

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

      In that case in loop give another if statement that if at any point your farthest is less than i then return -1 .. i.e
      If(farthest

  • @Vishaljoshi-uo6yc
    @Vishaljoshi-uo6yc 2 ปีที่แล้ว

    we have to run our loop for (

    • @Vishaljoshi-uo6yc
      @Vishaljoshi-uo6yc 2 ปีที่แล้ว

      which means

    • @arshdeep011
      @arshdeep011 2 ปีที่แล้ว

      Because n-1 is last element,, we need not to check for that

  • @arshdeep011
    @arshdeep011 2 ปีที่แล้ว

    Thanks di

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

    When you are not able to reach the last index, return -1, slight changes in code as shown below
    int farthest = 0, jumps = 0, curr = 0;
    //edge case
    if(arr[0] == 0)
    return -1;
    for(int i=0; i

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

      In the question it's written that we will reach the last index anyhow. so this piece of code is not needed.

  • @rabindradocument8934
    @rabindradocument8934 2 ปีที่แล้ว

    Steps vs Jumps

  • @010amityadav7
    @010amityadav7 2 ปีที่แล้ว

    if possible please teach in Hindi

  • @rounakdutta6164
    @rounakdutta6164 3 ปีที่แล้ว

    if the curr becomes >= lastIndex, we can break from the for loop, then there will be fewer number of iterations. a little more optimized.

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

    Kuch samaj nahi aaya

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

    Aunty at 1:21 😂