3709. Design Exam Scores Tracker Medium
1/**
2 * [3709] Design Exam Scores Tracker
3 *
4 * Alice frequently takes exams and wants to track her scores and calculate the total scores over specific time periods.
5 * Implement the ExamTracker class:
6 *
7 * ExamTracker(): Initializes the ExamTracker object.
8 * void record(int time, int score): Alice takes a new exam at time time and achieves the score score.
9 * 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.
10 *
11 * It is guaranteed that the function calls are made in chronological order. That is,
12 *
13 * Calls to record() will be made with strictly increasing time.
14 * 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.
15 *
16 *
17 * <strong class="example">Example 1:
18 * <div class="example-block">
19 * Input:<br />
20 * <span class="example-io">["ExamTracker", "record", "totalScore", "record", "totalScore", "totalScore", "totalScore", "totalScore"]<br />
21 * [[], [1, 98], [1, 1], [5, 99], [1, 3], [1, 5], [3, 4], [2, 5]]</span>
22 * Output:<br />
23 * <span class="example-io">[null, null, 98, null, 98, 197, 0, 99] </span>
24 * Explanation
25 * ExamTracker examTracker = new ExamTracker();<br />
26 * examTracker.record(1, 98); // Alice takes a new exam at time 1, scoring 98.<br />
27 * examTracker.totalScore(1, 1); // Between time 1 and time 1, Alice took 1 exam at time 1, scoring 98. The total score is 98.<br />
28 * examTracker.record(5, 99); // Alice takes a new exam at time 5, scoring 99.<br />
29 * examTracker.totalScore(1, 3); // Between time 1 and time 3, Alice took 1 exam at time 1, scoring 98. The total score is 98.<br />
30 * examTracker.totalScore(1, 5); // Between time 1 and time 5, Alice took 2 exams at time 1 and 5, scoring 98 and 99. The total score is 98 + 99 = 197.<br />
31 * examTracker.totalScore(3, 4); // Alice did not take any exam between time 3 and time 4. Therefore, the answer is 0.<br />
32 * examTracker.totalScore(2, 5); // Between time 2 and time 5, Alice took 1 exam at time 5, scoring 99. The total score is 99.</div>
33 *
34 * Constraints:
35 *
36 * 1 <= time <= 10^9
37 * 1 <= score <= 10^9
38 * 1 <= startTime <= endTime <= t, where t is the value of time from the most recent call of record().
39 * Calls of record() will be made with strictly increasing time.
40 * After ExamTracker(), the first function call will always be record().
41 * At most 10^5 calls will be made in total to record() and totalScore().
42 *
43 */
44pub struct Solution {}
45
46// problem: https://leetcode.com/problems/design-exam-scores-tracker/
47// discuss: https://leetcode.com/problems/design-exam-scores-tracker/discuss/?currentPage=1&orderBy=most_votes&query=
48
49// submission codes start here
50
51struct ExamTracker {
52 false
53 }
54
55
56/**
57 * `&self` means the method takes an immutable reference.
58 * If you need a mutable reference, change it to `&mut self` instead.
59 */
60impl ExamTracker {
61
62 fn new() -> Self {
63
64 }
65
66 fn record(&self, time: i32, score: i32) {
67
68 }
69
70 fn total_score(&self, start_time: i32, end_time: i32) -> i64 {
71
72 }
73}
74
75/**
76 * Your ExamTracker object will be instantiated and called as such:
77 * let obj = ExamTracker::new();
78 * obj.record(time, score);
79 * let ret_2: i64 = obj.total_score(startTime, endTime);
80 */
81
82// submission codes end
83
84#[cfg(test)]
85mod tests {
86 use super::*;
87
88 #[test]
89 fn test_3709() {
90 }
91}
92Back
© 2026 bowen.ge All Rights Reserved.