Find the racer with the single fastest lap in F1 race data

Quick Overview

Given F1 lap records as pairs of racer name and lap time string, return the racer with the single fastest lap, breaking ties by the lexicographically smallest name. Tests a one-pass minimum scan, numeric parsing of string times, and a precise tie-break rule.

Find the racer with the single fastest lap in F1 race data

Company: Atlassian

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

You are given F1 race data as a list `race_data`, where each element is a pair `[racer_name, lap_time]` representing a single lap recorded during a race. The `racer_name` is a string and `lap_time` is a string representation of a floating-point number in seconds. Return the name of the racer who achieved the fastest lap (the single minimum lap time) across all the data. If multiple racers share the same fastest lap time, return the one whose name comes first lexicographically. ### Function Signature ```python def fastest_lap(race_data: list[list[str]]) -> str: ``` ### Rules - Lap times are compared by numeric value, so `"71.5"` and `"71.500"` are the same time. - A racer can appear in many entries. Only the single fastest lap counts, not a racer's average or total. - Lexicographic order is plain character-code order (Python's default `<` on strings): uppercase letters sort before lowercase letters, a space sorts before any letter, and a name that is a prefix of another name sorts first. ### Constraints - `1 <= len(race_data) <= 10^5` - Each element is `[racer_name, lap_time]` - `racer_name` consists of lowercase and uppercase English letters and spaces - `1 <= len(racer_name) <= 100` - `0.001 <= lap_time <= 999.999` - `lap_time` is a string representation of a float with up to 3 decimal places ### Examples ```text Input: race_data = [["Max Verstappen","72.584"],["Lewis Hamilton","71.230"],["Charles Leclerc","72.105"],["Lewis Hamilton","70.981"],["Max Verstappen","71.002"],["Charles Leclerc","71.500"]] Output: "Lewis Hamilton" ``` Lewis Hamilton recorded a lap time of 70.981, which is the fastest lap across all entries. Max Verstappen's best was 71.002 and Charles Leclerc's best was 71.500. ```text Input: race_data = [["Alice","85.123"],["Bob","85.123"],["Charlie","85.123"]] Output: "Alice" ``` All three racers share the same fastest lap time of 85.123, and "Alice" is the lexicographically smallest name. ```text Input: race_data = [["bob","60.5"],["Bob","60.500"],["Ann","61.000"]] Output: "Bob" ``` "60.5" and "60.500" are the same time, so "bob" and "Bob" tie for the fastest lap. Uppercase "B" has a smaller character code than lowercase "b", so "Bob" comes first even though "bob" appears earlier in the input.

Overview: Given F1 lap records as pairs of racer name and lap time string, return the racer with the single fastest lap, breaking ties by the lexicographically smallest name. Tests a one-pass minimum scan, numeric parsing of string times, and a precise tie-break rule.

Atlassian logo
Atlassian
Nov 25, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

You are given F1 race data as a list race_data, where each element is a pair [racer_name, lap_time] representing a single lap recorded during a race. The racer_name is a string and lap_time is a string representation of a floating-point number in seconds.

Return the name of the racer who achieved the fastest lap (the single minimum lap time) across all the data. If multiple racers share the same fastest lap time, return the one whose name comes first lexicographically.

Function Signature

def fastest_lap(race_data: list[list[str]]) -> str:

Rules

  • Lap times are compared by numeric value, so "71.5" and "71.500" are the same time.
  • A racer can appear in many entries. Only the single fastest lap counts, not a racer's average or total.
  • Lexicographic order is plain character-code order (Python's default < on strings): uppercase letters sort before lowercase letters, a space sorts before any letter, and a name that is a prefix of another name sorts first.

Constraints

  • 1 <= len(race_data) <= 10^5
  • Each element is [racer_name, lap_time]
  • racer_name consists of lowercase and uppercase English letters and spaces
  • 1 <= len(racer_name) <= 100
  • 0.001 <= lap_time <= 999.999
  • lap_time is a string representation of a float with up to 3 decimal places

Examples

Input: race_data = [["Max Verstappen","72.584"],["Lewis Hamilton","71.230"],["Charles Leclerc","72.105"],["Lewis Hamilton","70.981"],["Max Verstappen","71.002"],["Charles Leclerc","71.500"]]
Output: "Lewis Hamilton"

Lewis Hamilton recorded a lap time of 70.981, which is the fastest lap across all entries. Max Verstappen's best was 71.002 and Charles Leclerc's best was 71.500.

Input: race_data = [["Alice","85.123"],["Bob","85.123"],["Charlie","85.123"]]
Output: "Alice"

All three racers share the same fastest lap time of 85.123, and "Alice" is the lexicographically smallest name.

Input: race_data = [["bob","60.5"],["Bob","60.500"],["Ann","61.000"]]
Output: "Bob"

"60.5" and "60.500" are the same time, so "bob" and "Bob" tie for the fastest lap. Uppercase "B" has a smaller character code than lowercase "b", so "Bob" comes first even though "bob" appears earlier in the input.