There are n
players. They have to collect m
points. All the players and coins are in 1-D space i.e. on a number line. The initial location of all the players is given as the array players
where players[i]
denotes the location of the i
th player. The location of all the points is given as another array points
where points[i]
denotes the location of the i
th point. In one second a player can either move 1 step left or 1 step right or not move at all. A point is considered collected if any of the n
players had visited the point's location. The players can move simultaneously and independently of each other every second.
The task is to find the minimum time (in seconds) required to collect all the points if players act optimally.
Note: Locations of players and points are not necessarily given in sorted order.
Function Description
Complete the function getMinimumTime
in the editor below. The function must return an integer; the minimum time required to collect all the points
getMinimumTime
has the following parameters:
players[players[0]...players[n-1]]
: an array of integers denoting the locations of playerspoints[points[0]...points[m-1]]
: an array of integers denoting the locations of points
Example 1:
Input: players = [3, 6, 7], points = [2, 4, 7, 9]
Output: 2
Explanation:All the points can be collected in 2 seconds:It can be proved that we can't collect all the points in less than 2 seconds. Hence the answer is 2.
- The first player can collect points at [2] in one second.
- The second player can collect points at [4] in 2 seconds.
- The third player can collect points at [7, 9] in 2 seconds, first collecting the point at 7 and then moving to location 9.
1 ≤ n, m ≤ 10^5
1 ≤ players[i], points[i] ≤ 10^9

input:
output: