Design and implement a simple rating system (like movie/book reviews) that supports adding ratings and querying summary statistics.
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:
score
is an integer in
[1, 5]
.
(itemId, userId)
pair should have at most one active rating.
You may assume item and user IDs are strings or integers.
Provide the time/space complexity of each operation.