PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates a candidate's competency in designing and implementing data structures and algorithms for maintaining dynamic aggregates (total counts, sums, and averages) across user-item ratings while handling additions, updates, and removals.

  • medium
  • Atlassian
  • Coding & Algorithms
  • Software Engineer

Design a rating aggregator that returns totals and averages

Company: Atlassian

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Design and implement a simple rating system (like movie/book reviews) that supports adding ratings and querying summary statistics. #### Requirements Implement a data structure/class that supports the following operations: - `addRating(itemId, userId, score)`: user gives an item a numeric rating. - `updateRating(itemId, userId, newScore)`: user updates their rating (if it exists). - `removeRating(itemId, userId)`: user deletes their rating (if it exists). - `getItemStats(itemId)`: return at least: - total number of ratings - sum of scores - average score #### Notes - `score` is an integer in `[1, 5]`. - Multiple users can rate the same item, but each `(itemId, userId)` pair should have at most one active rating. - Aim for efficient updates and queries. You may assume item and user IDs are strings or integers. Provide the time/space complexity of each operation.

Quick Answer: This question evaluates a candidate's competency in designing and implementing data structures and algorithms for maintaining dynamic aggregates (total counts, sums, and averages) across user-item ratings while handling additions, updates, and removals.

Support add, update, remove, and stats operations for per-item user ratings.

Constraints

  • Scores are 1..5

Examples

Input: ((('add', 'm', 'u1', 5), ('add', 'm', 'u2', 3), ('stats', 'm')),)

Expected Output: [{'count': 2, 'sum': 8, 'average': 4.0}]

Explanation: Two ratings.

Input: ((('add', 'm', 'u1', 5), ('update', 'm', 'u1', 1), ('stats', 'm')),)

Expected Output: [{'count': 1, 'sum': 1, 'average': 1.0}]

Explanation: Update existing rating.

Input: ((('add', 'm', 'u1', 5), ('remove', 'm', 'u1'), ('stats', 'm')),)

Expected Output: [{'count': 0, 'sum': 0, 'average': None}]

Explanation: Remove rating.

Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Find a secret word using match feedback - Atlassian (hard)
  • Compute a moving average on a stream - Atlassian (hard)
  • Implement sliding-window rate limiter function - Atlassian (medium)
  • Implement sequential and parallel URL requests - Atlassian (medium)
  • Merge intervals and design rating APIs - Atlassian (medium)