MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / kangaroo

Function kangaroo

Hackerrank_problems/kangaroo/solution5.cpp:26–58  ·  view source on GitHub ↗

Complete the kangaroo function below.

Source from the content-addressed store, hash-verified

24
25// Complete the kangaroo function below.
26string kangaroo(int x1, int v1, int x2, int v2)
27{
28 if((x1>x2 && v1>v2) || (x2>x1 && v2>v1))
29 return "NO";
30 else if(x1==x2)
31 return "YES";
32 else
33 {
34 int max,min,max_speed,min_speed;
35 if(x1>x2)
36 {
37 max = x1;
38 max_speed = v1;
39 min = x2;
40 min_speed = v2;
41 }
42 else
43 {
44 max = x2;
45 max_speed = v2;
46 min = x1;
47 min_speed = v1;
48 }
49 while(max>min)
50 {
51 max+=max_speed;
52 min+=min_speed;
53 if(max==min)
54 return "YES";
55 }
56 return "NO";
57 }
58}
59
60int main()
61{

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected