Median Rating of Most Recent N Comments
Asked at Amazon · Coding Questions · Difficulty: Hard
Comments arrive as a stream, each with an integer `rating`. Support `add(x)` (append a comment) and `median()` (median rating of the most recent `N` comments, or all of them if fewer than `N` exist). For an even count return the average of the two middle values as a float.
Loading the problem…