Get Max Racers
Updated
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):
int speed[n]: the speeds of the racersint 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 = 3Remove 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, wherenis the length ofspeed1 <= k <= n1 <= 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