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

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

Nikhil Lohia

3 года назад

16,078 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Atrika show
Atrika show - 27.10.2023 17:00

Thank you for this video Sir.
Just in first if operator it will be
if(v1 <= v2)
return "NO"

Ответить
JaBroCode
JaBroCode - 03.10.2023 04:39

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 <= because input might depict v2=v1

Ответить
Saritha Annadurai
Saritha Annadurai - 29.08.2023 22:50

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

Ответить
Rangith G
Rangith G - 02.08.2023 17:19

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

Ответить
Abhinav Gupta
Abhinav Gupta - 05.03.2023 21:08

relative velocity is also a way

Ответить
Vanipenta Balaji
Vanipenta Balaji - 28.02.2023 07:30

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

Ответить
MD Riyaz Aly
MD Riyaz Aly - 23.12.2022 08:13

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

if((x2-x1)%(v1-v2) == 0){
return "YES";
}else{
return "NO";
}

velocity should not be equal check this

Ответить
First JM
First JM - 01.12.2022 19:23

👍

Ответить
Pratik Khadtale
Pratik Khadtale - 26.09.2022 06:14

what to do when you are stuck ??

Ответить
Abdessamad Sayhi
Abdessamad Sayhi - 15.09.2022 13:48

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<= v2): return "NO"
The rest is fine.

Ответить
Anmol Verma
Anmol Verma - 27.08.2022 12:07

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

Ответить
Zheng Feng Cheah
Zheng Feng Cheah - 21.08.2022 05:30

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 ?

Ответить
Rahul Wadwani
Rahul Wadwani - 07.08.2022 00:42

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

Ответить
Nawaz Pasha
Nawaz Pasha - 03.07.2022 07:59

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

Ответить
israel Jerônimo
israel Jerônimo - 13.05.2022 22:18

Good job man!

Ответить
Girja shankar
Girja shankar - 13.04.2022 08:11

one error in this solution,instead of only applying if(v1<v2) we should apply (v1<=v2 ) because kangaroo 1 is always behind kangaroo 2 and cant meet even if v1==v2 and can also cause divided by zero exception according to solution

Ответить
JOSHNA JEEVITHA
JOSHNA JEEVITHA - 02.04.2022 14:48

if(v1<=v2) return "NO";
instead of if(v1<v2)
Test case: 43 2 70 2 to test

Ответить
Anuj Sharma
Anuj Sharma - 27.03.2022 19:58

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

Ответить
motion kings
motion kings - 16.01.2022 15:01

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

Ответить
Ji-yoon
Ji-yoon - 15.01.2022 07:29

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

Ответить
Vengatesh TR
Vengatesh TR - 29.12.2021 12:15

Good explanation, bro. Thank you

Ответить
Saumy Tiwari
Saumy Tiwari - 18.11.2021 00:03

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

Ответить
sierra wants a snacc
sierra wants a snacc - 05.11.2021 02:08

love your explanation! keep it up!

Ответить
Jaron Ritter
Jaron Ritter - 29.10.2021 09:40

I tried this and it failed several test cases

Ответить
Shruti Paliwal_IT_105
Shruti Paliwal_IT_105 - 17.10.2021 12:51

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

Ответить
Champion
Champion - 06.10.2021 10:14

please try to speak a little louder

Ответить
Vigneshwaran R
Vigneshwaran R - 23.09.2021 17:45

what if v1 = v2 then formula won't work

Ответить
Dips Coding Tutorials
Dips Coding Tutorials - 22.05.2021 04:57

Your method is very useful and easily understood.

Ответить