Author: Setter’s Name
Tester: Tester’s Name
Editorialist: Editorialist’s name



There are two rabbits on an x-axis ready to jump in the positive direction (i.e, toward positive infinity). The first rabbit starts at location x1 and moves at a rate of v1 feet per jump. The second rabbit starts at location x2 and moves at a rate of v2 feet per jump. Given the starting locations and movement rates for each rabbit, can you determine if they’ll ever land at the same location at the same time?
Note : The two rabbits must land at the same location after making the same number of jumps.
using namespace std;
int main() {
int x1,x2,v1,v2,flag=0;
if(x1==x2&&v1==v2) cout<<“YES”<<endl;
else cout<<“NO”<<endl;
if(x1==x2){ cout<<“YES”;flag=1; break; }
if(!flag) cout<<“NO”<<endl;
return 0;
Example case 1 : If the Input is (0 3 4 2) ,then the two rabbits jump through the following sequence of locations:
0 -> 3 -> 6 -> 9 -> 12
4 -> 6 -> 8 ->10 -> 12
Thus, the rabbits meet after 4 jumps and we print YES.
Example case 2 : If the Input is (0 2 5 3) ,then the second rabbit has a starting location that is ahead (further to the right) of the first rabbits’s starting location (i.e., x2 > x1). Because the second rabbit moves at a faster rate (ie., v2 > v1 ) and is already ahead of the first rabbit, the first rabbit will never be able to catch up. Thus, we print NO.