FastPrepThrow The Ball
Problems/Throw The Ball

Throw The Ball

Flexport logoFlexport● MediumFULLTIMEOA

Updated Jul 2026

QuestionFunctionExamplesConstraints

Problem statement

In a park, there are n friends standing in a random order, and they plan to throw a ball around. Each friend has a unique number in the range from 1 to n, inclusive. The i-th friend always throws the ball to the friend given by receiver[i], and one throw happens each second. Friend 1 starts with the ball, and every friend throws to another friend.

Determine which friend has the ball after seconds seconds.

Note: Friends are numbered starting from 1.

The function receives the following parameters:

  1. int receiver[n]: receiver[i] is the friend who receives the ball from the i-th friend.
  2. long seconds: the number of seconds that the game lasts.

Return the int identifier of the friend holding the ball after seconds seconds.

Function

throwTheBall(receiver: int[], seconds: long) → int

Examples

Example 1

receiver = [2, 4, 1, 5, 3]seconds = 6return = 2

After 6 seconds, the ball is with friend 2.

Constraints

  • 2 ≤ n ≤ 10^5
  • 1 ≤ receiver[i] ≤ n (receiver[i] ≠ i)
  • 1 ≤ seconds ≤ 10^12

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
  • Matrix TraversalOA · Seen Feb 2024
  • Collect PointsOA · Seen Feb 2024
  • Malware SpreadOA · Seen Feb 2024

Similar questions at other companies

  • Count Lamps Lighting Each PointAirbnb · OAAirbnb interview questions
  • Count Pairs of Overlapping SquaresCapital One · OACapital One interview questions
  • Bank Accounts with Balance HistoryMeta · OAMeta interview questions
  • Maximum Interactive Team SizeMicrosoft · OAMicrosoft interview questions
  • Index of the Maximum After Left RotationsChubb · OAChubb interview questions
  • Rolling MetricsAkuna Capital · OAAkuna Capital interview questions
  • Longest Increasing Price SubsequenceOpenAI · OAOpenAI interview questions
  • Linear InterpolatorTwo Sigma · OATwo Sigma interview questions
  • Rock JumpingIMC Trading · OAIMC Trading interview questions
  • Find Sum of BeautiesAmazon · OA

Flexport interview experiences

  • Flexport interviews · 2026
All Flexport interview questionsSee Flexport hiring insights
Saved
class Solution {
    public int throwTheBall(int[] receiver, long seconds) {
      // write your code here
    }

}
Checking account…