Logger Rate Limiter

Try to solve the Logger Rate Limiter problem.

Statement

For the given stream of message requests and their timestamps as input, you must implement a logger rate limiter system that decides whether the current message request is displayed. The decision depends on whether the same message has already been displayed in the last SS seconds. If yes, then the decision is FALSE, as this message is considered a duplicate. Otherwise, the decision is TRUE.

Note: Several message requests, though received at different timestamps, may carry identical messages.

Constraint:

  • 11 \leq request.length 102\leq 10^{2}
  • 00 \leq timestamp 103\leq 10^{3}
  • Timestamps are in ascending order.
  • Messages can be written in lowercase or uppercase English alphabets.

Examples

Note: In the following examples, the time limit, SS, is set to 77.

1 of 3

Understand the problem

Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:

Logger Rate Limiter

1

Suppose the time limit for the following timestamps is 5. What will be the correct output sequence?

A)

TRUE
FALSE
FALSE
TRUE
FALSE
FALSE

B)

TRUE
TRUE
FALSE
TRUE
TRUE
FALSE

C)

TRUE
FALSE
FALSE
TRUE
FALSE
FALSE

Question 1 of 20 attempted

Figure it out!

We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.

Drag and drop the cards to rearrange them in the correct sequence.

Try it yourself

Implement your solution in the following coding playground:

Note: In the following test cases, the time limit, SS, is set to 77.

Press + to interact
C++
usercode > RequestLogger.cpp
#include <iostream>
#include <unordered_map>
#include <vector>
class RequestLogger {
private:
std::unordered_map<std::string, int> requests;
int timeLimit;
public:
RequestLogger(int newTimeLimit){
// Initialize your data structure here
}
bool MessageRequestDecision(int timestamp, std::string request) {
// Replace the placeholder return statement with your code
return false;
}
};