Quick Overview

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.

Implement agent voting with average and sorting

Company: Atlassian

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Design an in-memory “agent voting” module that records ratings agents give to items (e.g., tickets/articles). Requirements: - Each vote is: `(agentId, itemId, rating)` where `rating` is an integer (e.g., 1–5). - Support computing the **average rating** for a given `itemId`. - Support returning items **sorted by average rating** (descending). Specify how ties are broken (e.g., by `itemId` ascending). Clarify behaviors: - If the same agent votes on the same item multiple times, should the latest vote replace the previous one? - What should be returned for items with no votes? Provide the core data structures and methods, and analyze time/space complexity.

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.

Record item ratings by agent, replacing repeat votes by the same agent, and return averages or sorted items.

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.

Hints

  1. Maintain per-agent item votes plus per-item totals and voter counts.

Loading coding console...