You are given ‘N’ locations. You are provided with an integer representing the speed. You have to find the maximum time it will take traveling between any two locations.
Each location has two integer values representing the ‘x’ and ‘y’ coordinates, respectively.
Note:You have to use Euclidean distance i.e., sqrt((y2 - y1)^2 + (x2 - x1)^2)
You have to return the time with the precision of up to 6 decimal places.
For example:
You are given ‘locations’ = [[0, 2], [0, 0], [2, 0]], and ‘speed’ = 2, then the maximum time will be between points [0, 2], [2, 0] which is 1.41421356237. Hence the answer rounded up to 6 decimal places is 1.414214.
The first line of input contains the integer ‘T’ representing the number of test cases.
The first line of each test case contains two space-separated integers, 'N' and 'speed', representing the number of locations and speed, respectively.
The next ‘N’ lines contain two space-separated integers, ‘x’ and ‘y’, representing the point in coordinate space as a location.
Output Format:
For each test case, print a positive real number, up to 6 decimal places, representing the maximum time it will take traveling between any two locations.
Print a separate line for each test case.
1 <= T <= 10
1 <= N <= 10^5
1 <= speed <= 10^5
2 <= x, y <= 10^5
Time Limit: 1 sec
Note:
You do not need to print anything. It has already been taken care of. Just implement the function.
2
3 2
0 0
2 0
0 2
3 1
1 0
0 0
2 0
1.414214
2.000000
For the first test case, locations = [[0, 2], [0, 0], [2, 0]], and speed = 2, then the maximum time will be between points [0, 2], [2, 0] which is 1.41421356237. Hence the answer rounded up to 6 decimal places is 1.414214.
For the second test case, locations = [[1, 0], [0, 0], [2, 0]], and speed = 1, then the maximum time will be between points [0, 0], [2, 0] which is 2.0. Hence the answer rounded up to 6 decimal places is 2.000000.
2
4 2
0 2
0 3
0 4
0 1
2 2
1 0
1.500000
0.500000
Try to find the points with the maximum distance between them.
In this approach, we will sort all the points by their X Coordinates. Then we will iterate through every possible coordinate combination and find the maximum distance among all points.
Then divide the maximum distance by speed to find the maximum time.
Algorithm:
O(N^2), where N is the number of locations.
We are checking each location, and for each location, we are iterating over the whole array. This will take O(N^2) time. Hence the overall time complexity is O(N^2).
O(1),
No extra space is being used. Hence the overall space complexity is O(1).