#391 Counting Active Users in a Sliding Window
There is a sequence of user requests, where each request is a pair of time and userId. Requests always arrive sorted by time.
The system must quickly answer: “How many users made at least limit requests during the last k milliseconds?”, where k > 0 and limit > 0.
class UserStatistics {
private long limit = 0;
private long k = 0;
public void event(long now, long userId) {
// place your code here
}
public int robotCount(long now) {
// place your code here
}
}
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor