We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Hey everyone, I've come up with a solution to a kangaroo problem and I'm excited to share it with you all. I would greatly appreciate your feedback on my solution, as I'm always looking to improve and learn from others. Feel free to review and provide your thoughts. Thanks in advance!
publicstaticStringkangaroo(intx1,intv1,intx2,intv2){// Write your code hereintjumps=0;if(x1>x2&&v1<v2){while(x1!=x2){x1=x1+v1;x2=x2+v2;jumps++;if(x2>x1)return"NO";}return"YES";}elseif(x2>x1&&v2<v1){while(x2!=x1){x1=x1+v1;x2=x2+v2;jumps++;if(x1>x2)return"NO";}return"YES";}return"NO";}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Number Line Jumps
You are viewing a single comment's thread. Return to all comments →
Hey everyone, I've come up with a solution to a kangaroo problem and I'm excited to share it with you all. I would greatly appreciate your feedback on my solution, as I'm always looking to improve and learn from others. Feel free to review and provide your thoughts. Thanks in advance!