Algorithms and Data Structures · Middle · Question 68 of 75
Which problem is solved by keeping the k most recent values in a fixed-size ring buffer?
- ✓Correct answer: Keeping the last k events, like recent logs or a moving average
- 2Finding the k largest values seen in the stream so far
- 3Sorting a stream of numbers in real time as they arrive
Explanation
A ring buffer overwrites the oldest entry when it's full, with O(1) writes and no shifting. The k largest values need a heap, not a ring buffer.