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.
🎯 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
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
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.
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.
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
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 .
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
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.
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")
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 :)
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
Thank you sir!!
One of the greatest explanation given by any teacher.
Thank you for this video Sir.
Just in first if operator it will be
if(v1
Wow......what a clear explanation. Thanks
one error in this solution,instead of only applying if(v1
thanks buddy
Yes!
yes, you are right. thanks
Genius 🎉
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.
Your method is very useful and easily understood.
if(v1
🎯 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
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
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.
Very good explanation, sir ! Thank you !
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.
love your explanation! keep it up!
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
thanks for pointing that out, I have fixed the code on Github.
thank you bro.....this case was abrupting my whole code.
Good explanation, bro. Thank you
Easy explanations, Thank you for your effort. I subscribed Nikhil!
if you like solutions like these, consider joining my channel: ua-cam.com/channels/T-S2ngqEBoYCM5UKuNeELg.htmljoin
Good job man!
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
yeah, it is.
Thank you
Which mathematics chapter concept or formula did you have used here? Is it polynomials? Or? Thank you 👍 Anyone
we know that kangaroo2 starting position is higher so if v2 >= v1 then its obvs "NO"
Correct
relative velocity is also a way
I am comparing speeds in my method…that is infact relative velocity.
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?
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
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
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 ?
The formula will not work if v2 > v1
As (v1 - v2) will give you a negative number then
how (4,5,2,3) works can any one explain.. whether kangaro jumping backward
can you please elaborate what do you want to ask?
it won't be the test case because constraint says x1
what if v1 = v2 then formula won't work
If v1=v2, then the kangaroos will never meet.
@@nikoo28 thanks
👍
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 .
Why that formula gives a remainder of zero then only we reach at our amswer
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
if(v2 >= v1){
return "NO";
}
if((x2-x1)%(v1-v2) == 0){
return "YES";
}else{
return "NO";
}
velocity should not be equal check this
what to do when you are stuck ??
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.
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")
I tried this and it failed several test cases
Check out the link in description to my github profile if you are facing a problem while implementing this. :)
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 :)
use the following:
if(v1 > v2)
{
int r = (x2 - x1)%(v1 - v2);
if(r == 0)
{
return "YES";
}
}
return "NO";
solution is wrong if v1==v2 the denominator becomes 0 it will raise an error
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 :)
please try to speak a little louder
Have a look at my latest videos. I made some modifications to the audio.
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
Check the code in the given link in video description. That should help you to debug.
@@nikoo28 that's working but what about my code?
This is running well except one case.
Are you able to download the failing test case?