We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Your logic is wrong. The correct brute force approach is:
import java.io.;
import java.util.;
import java.text.;
import java.math.;
import java.util.regex.*;
public class Solution
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int x1 = in.nextInt();
int v1 = in.nextInt();
int x2 = in.nextInt();
int v2 = in.nextInt();
int c=0;
int k1 = x1;
int k2 = x2;
if(x2>x1&&v2>v1)
System.out.print("NO");
else
{
for(int i=0;i<10000;i++)
{
k1+=v1;
k2+=v2;
if(k1==k2)
{
c++;
break;
}
}
if(c!=0)
System.out.print("YES");
else
System.out.print("NO");
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Number Line Jumps
You are viewing a single comment's thread. Return to all comments →
Your logic is wrong. The correct brute force approach is: import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;
public class Solution {
}