Problem 195099 · medium · Phase 01 Prerequisites & Setup

League Leaderboard

loops · dictionaries · sorting · strings

events is a list of [team, points] pairs recorded during a season (points may be negative for penalties). Total each team's points and return the leaderboard as a list of strings "team: total", ordered from highest total to lowest. Teams with equal totals are ordered alphabetically by name.

Examples

Input:  events = [["red", 3], ["blue", 5], ["red", 4], ["green", 7]]
Output: ["green: 7", "red: 7", "blue: 5"]

Input:  events = [["x", 1]]
Output: ["x: 1"]

Constraints

  • 0 <= len(events) <= 1000; team names are lowercase words.

Goals

  • Accumulate totals per team from a stream of events
  • Sort by score descending with an alphabetical tie-break
  • Format results as strings
Starting Python…