Basically it was a https://leetcode.com/problems/design-hit-counter/ but the interesting part is a follow-up.
The range is not a constant but the second argument of getHits function and it should be done in less than O(n) memory.
E.g.
Having:
hit(1), hit(1) hit(1), hit(2), hit(2), hit(3);
Result should be:
getHits(5, 1) -> 0
getHits(5, 2) -> 0
getHits(5, 3) -> 1 (3)
getHits(5, 4) -> 3 (2, 2, 3)
getHits(5, 5) -> 6 (1, 1, 1, 2, 2, 3)
First argument still may vary, but can't be less than last recorded timestamp, since we maintain a chronological order. I just make it 5 to not confuse you with other inputs.
Interviewer was trying to gave me some hints, but I was not able to solve it in less than O(n) memory. Looks like he was trying to guide me through some cumulative sum manipulations, but I'm not sure.