The Jumping Kangaroo || codechef Solution In Java

 Solution:

import java.util.Scanner;


public class Main {

public static void main(String [] args){

Scanner sc = new Scanner(System.in);

int x1 = sc.nextInt(), v1 = sc.nextInt();

int x2 = sc.nextInt(), v2 = sc.nextInt();

int count1 = 0;

int count2 = 0;

int distance1 = x1;

int distance2 = x2;

boolean flag = true;

while(flag){

distance1 += v1;

count1++;

distance2 += v2;

count2++;

if(count1==count2 && distance1==distance2){

System.out.println("YES");

flag = false;

}

if(count1==count2 && Math.abs(distance1-distance2)>Math.abs((distance1-v1)-(distance2-v2))){

System.out.println("NO");

flag = false;

}

if(v1==v2){

System.out.println("NO");

flag = false;

}

}

}

}

The Jumping Kangaroo || codechef Solution In Java The Jumping Kangaroo || codechef Solution In Java Reviewed by CodexRitik on November 06, 2020 Rating: 5

No comments:

Powered by Blogger.