FastPrepCollect Points
Problems/Collect Points

Collect Points

Flexport logoFlexport● MediumFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

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 ith player. The location of all the points is given as another array points where points[i] denotes the location of the ith 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

getMinimumTime(players: int[], points: int[]) → int

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:

  1. players[players[0]...players[n-1]]: an array of integers denoting the locations of players
  2. points[points[0]...points[m-1]]: an array of integers denoting the locations of points

Examples

Example 1

players = [3, 6, 7]points = [2, 4, 7, 9]return = 2

All the points can be collected in 2 seconds:

  • 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.

It can be proved that we can't collect all the points in less than 2 seconds. Hence the answer is 2.

Constraints

  • 1 ≤ n, m ≤ 10^5
  • 1 ≤ players[i], points[i] ≤ 10^9

More Flexport interview questions

  • Container Ledger with TradesONSITE INTERVIEW · Seen Nov 2026
  • Apply Operations to Make a String EmptyPHONE SCREEN · Seen Nov 2026
  • Max Area of Island Without Changing the GridPHONE SCREEN · Seen Nov 2026
  • Choose the Next Hidden-Word GuessONSITE INTERVIEW · Seen Jul 2026
  • Count Good SubsequencesOA · Seen Jun 2024
  • Distinct MovesOA · Seen Jun 2024
  • Hotspot ConnectionsOA · Seen Jun 2024
  • Throw The BallOA · Seen Jun 2024
  • Matrix TraversalOA · Seen Feb 2024
  • Malware SpreadOA · Seen Feb 2024

Similar questions at other companies

  • Find Minimum TimeAlphaSense · OA
  • Find Minimum TimeBlackRock · OABlackRock interview questions
  • Shortest Board Length to Cover HolesMicrosoft · OAMicrosoft interview questions
  • Minimize Maximum Group DifferenceDRW · OADRW interview questions
  • Minimum-Cost Solar Rooftop AllocationDeloitte · OADeloitte interview questions
  • K-Means ClusteringFortinet · OAFortinet interview questions
  • Playlist PartitioningTikTok · OATikTok interview questions
  • Get Minimum Pen Drive SizeAmazon · OA
  • Aggressive CowsPeopleStrong · OAPeopleStrong interview questions
  • Spread Cows Across StallsExpedia · OAExpedia interview questions

Flexport interview experiences

  • Flexport interviews · 2026
All Flexport interview questionsSee Flexport hiring insights
Saved
class Solution {
    public int getMinimumTime(int[] players, int[] points) {
        // write your code here
    }

}
Checking account…