← 返回 atlassian 的题目列表Agent Vote API Design
类型:online_judge
atlassian
Design an API for a system to handle agent voting situations, including the following features:
recordVote(String agentId, int score): Record a score for an agent, with a range of 1 to 5.
listAgentsWithAvgScore() -> List[Tuple[String, Float]]: Return a list containing each agent's ID and their average score.
listSortedAgentsByAvgScore() -> List[String]: Return a sorted list of agent IDs based on average score.
Implement a strategy to handle tie scores for agents. Implement the solution and provide test cases.
Test Cases:
recordVote("agentA", 3)
recordVote("agentB", 4)
recordVote("agentA", 5)
listAgentsWithAvgScore should return [('agentA', 4.0), ('agentB', 4.0)]
listSortedAgentsByAvgScore should return ["agentA", "agentB"] (or "agentB" first, depending on the tie-breaker rule)
Example
Input
recordVote('agentA', 3)
listAgentsWithAvgScore()