Implement agent voting with average and sorting
Company: Atlassian
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates the ability to design in-memory data structures and algorithms for recording and aggregating agent votes, including computing average ratings, sorting by aggregate score with tie-breaking, handling update semantics for repeated votes, and accounting for items with no votes.
Constraints
- Ratings are integers
Examples
Input: ((('vote', 'a', 'x', 5), ('vote', 'b', 'x', 3), ('avg', 'x')),)
Expected Output: [4.0]
Explanation: Average from two agents.
Input: ((('vote', 'a', 'x', 5), ('vote', 'a', 'x', 1), ('avg', 'x')),)
Expected Output: [1.0]
Explanation: Latest vote replaces previous.
Input: ((('vote', 'a', 'x', 4), ('vote', 'a', 'y', 5), ('sorted',)),)
Expected Output: [[('y', 5.0), ('x', 4.0)]]
Explanation: Sorted by average descending then item.
Hints
- Maintain per-agent item votes plus per-item totals and voter counts.