Box score trade ledger
MediumOnline Assessment
Build season scoring totals for a basketball league where players get traded mid-season.
You are given the opening rosters as [player, team] pairs, the season's trades as [day, player, new_team], and the lines of the box scores as [day, player, minutes, points]. Days are integers.
- A trade on day
dtakes effect from dayd + 1: games played on daydstill count for the old team. Several trades of the same player can occur; apply them in order of day, and for the same day in the order they are listed (the later one wins). - A line's team is the player's team on that line's day. Lines for players who are not on the opening rosters are ignored.
- If the same player has more than one line on the same day, the last one listed replaces the earlier ones (a stat correction).
- A line with
minutes == 0means the player did not play: it adds no game and no points. Every other line is one game played, and its points are added.
Input: rosters, trades and lines, as above.
Output: one row [player, team, games, points] for every (player, team) pair with at least one game, ordered by points descending, then by player ascending, then by team ascending. Names compare by plain alphabetical (code point) order.
Example 1
- Input:
- [[["Ava","Hawks"],["Bo","Hawks"]],[[3,"Ava","Owls"]],[[1,"Ava",30,14],[3,"Ava",28,16],[5,"Ava",25,12],[1,"Bo",20,5],[4,"Bo",22,7],[2,"Cy",20,9]]]
- Output:
- [["Ava","Hawks",2,30],["Ava","Owls",1,12],["Bo","Hawks",2,12]]
- Explanation
- Ava starts on the Hawks and is traded to the Owls on day 3. Her day-3 game still counts for the Hawks, since the trade applies from day 4: Hawks 2 games (days 1 and 3) and 30 points, Owls 1 game (day 5) and 12 points. Bo never moves: 2 games, 12 points. Cy is not on the opening rosters, so his line is ignored. Ava/Owls and Bo/Hawks tie on 12 points, so the player name decides.
Example 2
- Input:
- [[["Dan","Lions"]],[[2,"Dan","Wolves"],[2,"Dan","Bears"]],[[1,"Dan",30,11],[1,"Dan",30,20],[2,"Dan",0,0],[3,"Dan",12,6],[4,"Dan",20,8]]]
- Output:
- [["Dan","Lions",1,20],["Dan","Bears",2,14]]
- Explanation
- Dan starts on the Lions and is traded twice on day 2, first to the Wolves and then to the Bears; the later one wins, so from day 3 he plays for the Bears (no game was ever played for the Wolves). On day 1 his second line (20 points) replaces the first (11): Lions, 1 game, 20 points. His day-2 line has 0 minutes, so it is not a game. Days 3 and 4 give the Bears 2 games and 14 points.
Example 3
- Input:
- [[["Eve","Kings"],["Zed","Kings"]],[[6,"Eve","Suns"],[2,"Eve","Jets"]],[[1,"Eve",10,4],[4,"Eve",30,20],[7,"Eve",20,9],[1,"Zed",25,20]]]
- Output:
- [["Eve","Jets",1,20],["Zed","Kings",1,20],["Eve","Suns",1,9],["Eve","Kings",1,4]]
- Explanation
- The trades are listed out of order; by day Eve goes Kings (start), Jets from day 3 (traded day 2), Suns from day 7 (traded day 6). So day 1 is Kings (4 points), day 4 is Jets (20) and day 7 is Suns (9). Eve/Jets and Zed/Kings tie at 20 points, so the player name breaks the tie: Eve first.
Constraints
0 <= rosters.length <= 30,0 <= trades.length <= 40,0 <= lines.length <= 1501 <= day <= 10^6,0 <= minutes <= 48,0 <= points <= 100- Players are listed once on the opening rosters; names and team names are 1 to 12 letters; trades are not necessarily sorted by day