Back to problems

Median Rating of Most Recent N Comments

Algorithm · Amazon · Hard

Problem You are building a real-time comment system. Comments arrive continuously, and each one carries an integer rating. Implement two operations: add x – append a new comment whose rating is x (the rating may be negative, zero, or positive). median – return the median rating among only the most recent N comments. If fewer than N comments have been added so far, use all available comments. Median definition: When the number of considered ratings is odd, the median is the…

Checking your access…