-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkangaroo.cpp
More file actions
36 lines (29 loc) · 1.09 KB
/
kangaroo.cpp
File metadata and controls
36 lines (29 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
using namespace std;
string kangaroo(int x1, int v1, int x2, int v2) {
// x1 --> Starting Position Of Kangaroo 1
// x2 --> Starting Position Of Kangaroo 2
// v1 --> Steps Travelled Each Jump (Kangaroo 1)
// v2 --> Steps Travelled Each Jump (Kangaroo 2)
int maxGuess = 10000;
while ((x1 != x2) && (maxGuess >= 0)) {
x1 += v1;
x2 += v2;
maxGuess--;
}
if (x1 == x2) {
return "YES";
}
return "NO";
}
// Info: TestCases Worked
//int main() {
// cout << kangaroo(0, 3, 4, 2);
// return 0;
//}
/*
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.
*/