You are given race data from multiple Formula 1 races. The data is represented as a 2D array races, where races[i] is an array of strings representing lap entries for the i-th race.
Each lap entry is a string in the format "RacerName:LapTime", where RacerName is the name of the racer and LapTime is a positive integer representing the time (in seconds) for that lap.
Return the name of the racer who achieved the fastest (minimum) lap time across all races. If multiple racers share the same fastest lap time, return the one whose name comes first lexicographically.
Function Signature
def fastest_racer(races: list[list[str]]) -> str:
Rules
-
LapTime
is compared as an integer, so a lap of
99
is faster than a lap of
100
.
-
A racer can appear in several races and several times in one race. Only the single fastest lap across all races counts.
-
Names are taken exactly as written. Lexicographic order is plain character-code order (Python's default
<
on strings), so uppercase letters sort before lowercase letters.
Constraints
-
1 <= len(races) <= 100
-
1 <= len(races[i]) <= 1000
-
Each
races[i][j]
is a string in the format
"RacerName:LapTime"
-
LapTime
is a positive integer:
1 <= LapTime <= 10^5
-
RacerName
consists of uppercase and lowercase English letters only
Examples
Input: races = [["Hamilton:85","Verstappen:83","Leclerc:87"],["Hamilton:82","Verstappen:84","Leclerc:81"],["Hamilton:86","Verstappen:80","Leclerc:83"]]
Output: "Verstappen"
The fastest laps per racer are Hamilton 82, Verstappen 80 and Leclerc 81. Verstappen has the overall fastest lap of 80 seconds.
Input: races = [["Alice:90","Bob:90"],["Alice:85","Bob:85"]]
Output: "Alice"
Both Alice and Bob have a fastest lap of 85. Since "Alice" < "Bob" lexicographically, "Alice" is returned.
Input: races = [["bob:100","Bob:99"],["Ann:100","bob:99"]]
Output: "Bob"
The fastest lap is 99, shared by "Bob" and "bob". Uppercase "B" has a smaller character code than lowercase "b", so "Bob" comes first even though "bob" appears earlier in the input.