HackerRank - Number Line Jumps | Kangaroo | Full Solution with Visuals | Study Algorithms

Поділитися
Вставка
  • Опубліковано 16 гру 2024

КОМЕНТАРІ • 62

  • @anmolverma075
    @anmolverma075 2 роки тому +9

    Thank you sir!!
    One of the greatest explanation given by any teacher.

  • @atrikashow8118
    @atrikashow8118 Рік тому +3

    Thank you for this video Sir.
    Just in first if operator it will be
    if(v1

  • @Ji-yoon
    @Ji-yoon 2 роки тому +5

    Wow......what a clear explanation. Thanks

  • @girjashankar7925
    @girjashankar7925 2 роки тому +35

    one error in this solution,instead of only applying if(v1

    • @sushantodas1825
      @sushantodas1825 2 роки тому

      thanks buddy

    • @suyashsharma1527
      @suyashsharma1527 2 роки тому +1

      Yes!

    • @bunnytheweebster
      @bunnytheweebster Рік тому +1

      yes, you are right. thanks

    • @lngwnd1
      @lngwnd1 8 місяців тому

      Genius 🎉

    • @ClashRoyale-pt9zj
      @ClashRoyale-pt9zj 2 місяці тому +1

      in the problem description there's a constraint that says x2 is always greater than x1, so there's no need to check for equality *in the case of this problem.

  • @dipscodingtutorials5314
    @dipscodingtutorials5314 3 роки тому +2

    Your method is very useful and easily understood.

  • @joshnajeevitha687
    @joshnajeevitha687 2 роки тому +6

    if(v1

  • @aman_v3
    @aman_v3 4 місяці тому

    🎯 Key points for quick navigation:
    00:00:00 *🌟 Introduction to Problem*
    - Initial comments about understanding the formula and solving the problem,
    - Welcoming viewers to the video.
    00:02:00 *🦘 Explanation of Kangaroo Problem*
    - Starts explaining the positions and jumps of two kangaroos,
    - Describes the jumps and resulting positions of kangaroo 1 and kangaroo 2.
    00:05:21 *🔢 Distance and Jumps Calculation*
    - Discussion of the distance traveled by kangaroos based on their respective speeds,
    - Explains the equation to determine when kangaroos meet.
    00:07:09 *📊 Detailed Solution and Conclusion*
    - Breaks down the problem step-by-step,
    - Verifies if the kangaroos meet or not using derived formula,
    - Emphasizes on final solution and general problem-solving approach.
    00:09:35 *🧐 Final Thoughts and Insights*
    - Discusses applicability of mathematical skills and algorithms in computer programming,
    - Summarizes the central ideas of the problem,
    - Encourages viewers to subscribe for more content.
    Made with HARPA AI

  • @saumytiwari7
    @saumytiwari7 3 роки тому +2

    thankyou sir for the explanation.. i was worried that i am not able to understand a simple problem.. but now i get it.. BTW you look alike Techno Gamerz xD

  • @padmanabhans6632
    @padmanabhans6632 12 днів тому

    After reading the comments, while checking the velocities we should have to greater than or equal to operator
    if(v2>=v1) return "NO";
    then the Abort called issue is sorted.
    thanks guys.

  • @renanrosa5527
    @renanrosa5527 6 місяців тому

    Very good explanation, sir ! Thank you !

  • @ClashRoyale-pt9zj
    @ClashRoyale-pt9zj 2 місяці тому

    For anyone who wants to come here and say he's wrong about the first checking in the solution provided, according to the problem description in hackerrank, he isn't:
    There's a constraint mentioning that x2 is always greater than x1. There's no need then to check for equality *in the case of this problemm considering the constraints. Because of that, we could also (it is inneficient obviously) do all possible checks between jumps in a for loop that executes 10.000 times, because the constraints also say that all x and v are lower than 10.000.

  • @blobbybobi
    @blobbybobi 3 роки тому +1

    love your explanation! keep it up!

  • @abdessamadSayhi
    @abdessamadSayhi 2 роки тому +4

    Thanks for the easy explanation, but there is a situation where this code will not function.
    given these parameters: (43 2 70 2)
    The answer should be "NO", but your code return "YES"
    MY ANSWER BASED ON YOUR SOLUTION IS:
    - The first if statement should be like this: if(v1

    • @nikoo28
      @nikoo28  2 роки тому +3

      thanks for pointing that out, I have fixed the code on Github.

    • @champion_aarush
      @champion_aarush Рік тому

      thank you bro.....this case was abrupting my whole code.

  • @vsh-torch
    @vsh-torch 3 роки тому

    Good explanation, bro. Thank you

  • @SarithaAnnadurai
    @SarithaAnnadurai Рік тому

    Easy explanations, Thank you for your effort. I subscribed Nikhil!

    • @nikoo28
      @nikoo28  Рік тому

      if you like solutions like these, consider joining my channel: ua-cam.com/channels/T-S2ngqEBoYCM5UKuNeELg.htmljoin

  • @israeljeronimo3941
    @israeljeronimo3941 2 роки тому

    Good job man!

  • @JaBroCode
    @JaBroCode Рік тому +1

    Just so you know, u have all the code correct except for a little mistake in the first if operator in your code. It should be

  • @atulsingh7539
    @atulsingh7539 5 місяців тому

    Which mathematics chapter concept or formula did you have used here? Is it polynomials? Or? Thank you 👍 Anyone

  • @AnujTechShorts
    @AnujTechShorts 2 роки тому +2

    we know that kangaroo2 starting position is higher so if v2 >= v1 then its obvs "NO"

  • @AbhinavGupta-bj7qr
    @AbhinavGupta-bj7qr Рік тому +1

    relative velocity is also a way

    • @nikoo28
      @nikoo28  Рік тому

      I am comparing speeds in my method…that is infact relative velocity.

  • @chandrakumar424
    @chandrakumar424 9 місяців тому

    2 4 2 4
    I mean
    x1 = 2
    v1 = 4
    x2 = 2
    v2 = 4
    What is the correct answer?
    If have answer. this algo is working for this test case?

  • @bitwamet
    @bitwamet 2 роки тому

    I was able to crack only problem is based on the number of jumps should match not that one will stay and other will it reach just with multiple jumps

  • @motionkings
    @motionkings 2 роки тому

    but j is already an int type just like all other variables then obviously the division will have truncated value not like 3.54 or 6.7

  • @zhengfengcheah8725
    @zhengfengcheah8725 2 роки тому

    we had to put a if case for v2>v1, meaning the formula would work if V2>v1, giving an integer, but why does this scenario bypass the formula ?

    • @nikoo28
      @nikoo28  2 роки тому

      The formula will not work if v2 > v1
      As (v1 - v2) will give you a negative number then

  • @rangithg3702
    @rangithg3702 Рік тому

    how (4,5,2,3) works can any one explain.. whether kangaro jumping backward

    • @nikoo28
      @nikoo28  Рік тому

      can you please elaborate what do you want to ask?

    • @gmskapil
      @gmskapil Рік тому

      it won't be the test case because constraint says x1

  • @vikivarun6122
    @vikivarun6122 3 роки тому

    what if v1 = v2 then formula won't work

    • @nikoo28
      @nikoo28  3 роки тому +1

      If v1=v2, then the kangaroos will never meet.

    • @vikivarun6122
      @vikivarun6122 3 роки тому

      @@nikoo28 thanks

  • @firstjm9071
    @firstjm9071 2 роки тому

    👍

  • @padmanabhans6632
    @padmanabhans6632 12 днів тому

    Thanks bro, but at the test case this logic is inefficient cause the arguments are 43 2 70 2 and it would be 27/0=> it make Abort called.
    this happens to me after do the same thing you did bro.
    No offence please take look at this kindly help me through this .

  • @shrutipaliwal_it_1055
    @shrutipaliwal_it_1055 3 роки тому

    Why that formula gives a remainder of zero then only we reach at our amswer

    • @nikoo28
      @nikoo28  3 роки тому

      It is not the remainder…but look at the quotient. The quotient gives you the number of jumps. According to the question the jumps should be an integer… you cannot have a decimal jump…3.4, 7.8 number of jumps cannot be a decimal.
      So you want it to be an integer…and that will only happen when the remainder is 0

  • @mdriyazaly2036
    @mdriyazaly2036 2 роки тому

    if(v2 >= v1){
    return "NO";
    }

    if((x2-x1)%(v1-v2) == 0){
    return "YES";
    }else{
    return "NO";
    }
    velocity should not be equal check this

  • @pratikkhadtale3919
    @pratikkhadtale3919 2 роки тому

    what to do when you are stuck ??

    • @nikoo28
      @nikoo28  2 роки тому

      even a seasoned programmer will get stuck at many points in life. The more you practice, the more you will get stuck and the more you will be able to expose yourself to a variety of problems.
      That is the only way to get out...just keep training and be patient.

  • @VanipentaBalaji
    @VanipentaBalaji Рік тому

    bro its not working in python
    here is my code:
    x1,v1,x2,v2=map(int,input().split())
    if(v1 < v2):
    print("NO")
    if((x2-x1)%(v1-v2)==0):
    print("YES")
    else:
    print("NO")

  • @jaronritter4005
    @jaronritter4005 3 роки тому +1

    I tried this and it failed several test cases

    • @nikoo28
      @nikoo28  3 роки тому

      Check out the link in description to my github profile if you are facing a problem while implementing this. :)

    • @blobbybobi
      @blobbybobi 3 роки тому

      it only failed 1 test case when I tried. the reason is because of zero division error. just add error handling (e.g try, catch, finally etc) and it will pass all the test cases :)

    • @OGExperience
      @OGExperience 2 роки тому

      use the following:
      if(v1 > v2)
      {
      int r = (x2 - x1)%(v1 - v2);
      if(r == 0)
      {
      return "YES";
      }
      }
      return "NO";

  • @rahulwadwani9345
    @rahulwadwani9345 2 роки тому

    solution is wrong if v1==v2 the denominator becomes 0 it will raise an error

    • @nikoo28
      @nikoo28  2 роки тому

      In the ‘if’ condition we first check if v1 > v2.
      If v1==v2, then this will fail and it will return a “NO”
      Try it on your own :)

  • @champion5946
    @champion5946 3 роки тому +1

    please try to speak a little louder

    • @nikoo28
      @nikoo28  3 роки тому +1

      Have a look at my latest videos. I made some modifications to the audio.

  • @surajthakur5820
    @surajthakur5820 2 роки тому

    I solved this question using this code but in case 26 this is giving me an error please get this checked and do help me. Thanks in Advance:
    #include
    int main(){
    long int x1,x2,v1,v2,temp=0;
    scanf("%ld %ld %ld %ld",&x1,&v1, &x2, &v2);
    while(x1

    • @nikoo28
      @nikoo28  2 роки тому

      Check the code in the given link in video description. That should help you to debug.

    • @surajthakur5820
      @surajthakur5820 2 роки тому

      @@nikoo28 that's working but what about my code?
      This is running well except one case.

    • @nikoo28
      @nikoo28  2 роки тому

      Are you able to download the failing test case?