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.
Number Line Jumps
Number Line Jumps
Sort by
recency
|
3961 Discussions
|
Please Login in order to post a comment
Explanation: we have to print yes iff { x1+v1 x n= x2+v2 x n } we have constraint that x1< x2 so => ( v1-v2 )n=x2-x1 => n=(x2-x1)/(v1-v2)................n must be positive so v1>v2 and n is whole so the remainder should be 0 hence the code is as follows:
O(1) Solution
A brute-force approach with max_it equal to maximum size works for all test-cases:
My Java 8 Solution