FastPrepGet Max Racers
Problems/Get Max Racers

Get Max Racers

Amazon logoAmazon● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

HackerLand Sports Club wants to send a team for a relay race. There are n racers in the group indexed from 0 to n - 1. The ith racer has a speed of speed[i] units.

The coach decided to send some contiguous subsegments of racers for the race i.e. racers with index i, i + 1, i + 2 ..., j such that each racer has the same speed in the group to ensure smooth baton transfer. To achieve the goal, the coach decided to remove some racers from the group such that the number of racers with the same speed in some contiguous segment is maximum.

Given the array speed and an integer k, find the maximum possible number of racers in some contiguous segment of racers with the same speed after at most k racers are removed.

Function

getMaxRacers(speed: int[], k: int) → int

Complete the function getMaxRacers in the editor.

getMaxRacers has the following parameter(s):

  1. int speed[n]: the speeds of the racers
  2. int k: the maximum number of racers that can be removed

Returns int: the maximum number of racers that can be sent after removing at most k racers

Examples

Example 1

speed = [1, 4, 4, 2, 2, 4]k = 2return = 3

Remove the two racers with speed 2 (indices 3 and 4). The line becomes [1, 4, 4, 4], and the three racers with speed 4 now stand together. No speed appears more than 3 times (speed 4 appears 3 times), so no group can be larger. Return 3.

Constraints

  • 1 <= n <= 3 * 10^5, where n is the length of speed
  • 1 <= k <= n
  • 1 <= speed[i] <= 10^9

More Amazon interview questions

  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximal SquareONSITE INTERVIEW · Seen Nov 2026
  • Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Diagonal Traversal of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
  • Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
  • Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026

Similar questions at other companies

  • Get Message StatusSalesforce · OASalesforce interview questions
  • Count Servers With No Requests in a Time WindowIBM · OAIBM interview questions
  • Count Redundant File BackupsGoldman Sachs · OAGoldman Sachs interview questions
  • Count Subarrays with at Least K Equal-Fruit PairsTikTok · OATikTok interview questions
  • Maximum Valid Substring FrequencyMicrosoft · OAMicrosoft interview questions
  • Accept or Decline QueriesRamp · OARamp interview questions
  • Perfect SubstringAXQ Capital · OA
  • Consistent LogsRippling · OARippling interview questions
  • Longest Distinct StringSuperhuman · OASuperhuman interview questions
  • Longest Substring Without Repeating CharactersAkuna Capital · OAAkuna Capital interview questions

Interview reports that mention this question

  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
Saved
class Solution {
    public int getMaxRacers(int[] speed, int k) {
      // write your code here
    }

}
Checking account…