Design Exam Scores Tracker
medium · 43.9% accepted · 58 likes · top 26%
array · binary search · design · prefix sum
Description
Alice frequently takes exams and wants to track her scores and calculate the total scores over specific time periods.
Implement the ExamTracker class:
- ExamTracker(): Initializes the ExamTracker object.
- void record(int time, int score): Alice takes a new exam at time time and achieves the score score.
- long long totalScore(int startTime, int endTime): Returns an integer that represents the total score of all exams taken by Alice between startTime and endTime (inclusive). If there are no recorded exams taken by Alice within the specified time interval, return 0.
It is guaranteed that the function calls are made in chronological order. That is,
- Calls to record() will be made with strictly increasing time.
- Alice will never ask for total scores that require information from the future. That is, if the latest record() is called with time = t, then totalScore() will always be called with startTime <= endTime <= t.
Solution