Is there any mistake in that Cpp-code, which can lead unfavorable output ? Actually while submitting its solution...I got 6 wrong test cases, but I am not able to find any error!
I'm providing question(commented) for reference,
/* You are choreographing a circus show with various animals. For one act, you are given two
kangaroos on a number line ready to jump in the positive direction (i.e, toward positive infinity).
The first kangaroo starts at location x1 and moves at a rate of v1 meters per jump.
The second kangaroo starts at location x2 and moves at a rate of v2 meters per jump.
You have to figure out a way to get both kangaroos at the same location at the same time as part of
the show. If it is possible, return YES, otherwise return NO.
*/
#include <iostream>
int main()
{
int x1, v1, x2, v2;
std::cout << "ENTER FIRST STARTING POS THEN ITS SPEED:"<< std::endl;
std::cin >> x1 >> v1;
std::cout << "ENTER SECOND STARTING POS THEN ITS SPEED:"<< std::endl;
std::cin >> x2 >> v2;
int max, min;
(v1 > v2) ? max = x1, min = x2 : max = x2, min = x1;
while ((x1 != x2) && (min > max))
{
if (max == x1)
{
max = max + v1;
min = min + v2;
}
else
{
max = max + v2;
min = min + v1;
}
x1 = x1 + v1;
x2 = x2 + v2;
}
if (max == min)
{
std::cout << "YES";
}
else
std::cout << "NO";
return (0);
}