As reported: JPMorgan Chase SE3 (Q4 2025), R2: a volleyball score tracker behind the interface
GameTrackerwithvoid addMatch(String team1, String team2, String score)andString findFirst(), which returns the team with the highest score after the matches are recorded;findFirsthad to be faster thanO(n).
Implement the GameTracker class:
GameTracker()— creates an empty tracker.void addMatch(String team1, String team2, String score)— records one match.scorehas the form"p1-p2":team1scoredp1points andteam2scoredp2points in that match.String findFirst()— returns the team with the highest total score so far, where a team's total is the sum of the points it scored over all its recorded matches.
findFirst must run faster than O(n) in the number of teams.
Example
GameTracker()
addMatch("Eagles", "Hawks", "25-20") Eagles 25, Hawks 20
addMatch("Hawks", "Lions", "25-23") Hawks 45, Lions 23
findFirst() -> "Hawks"
addMatch("Lions", "Eagles", "25-10") Lions 48, Eagles 35
findFirst() -> "Lions"
Example 2
GameTracker()
findFirst() -> "" no matches yet
addMatch("Tigers", "Bears", "21-25")
findFirst() -> "Bears"
addMatch("Tigers", "Wolves", "4-0") Tigers 25, Bears 25
findFirst() -> "Bears" tie: alphabetically smaller name
Clarifications
findFirstmay be called at any time, between matches as well as at the end. Before any match it returns"".- Ties on total score go to the team whose name is lexicographically smaller.
- A team appears in the tracker once it has played a match, even with 0 points.
team1 ≠ team2; names are non-empty and contain no-.
Constraints: up to 10^5 calls in total; 0 ≤ p1, p2 ≤ 100.
Code runner format: two lines in LeetCode's design format — the method names, then their arguments, e.g. ["GameTracker","addMatch","findFirst"] and [[],["A","B","25-20"],[]]. The harness prints the list of return values (null for the constructor and addMatch).