Skip to main content
Back to problems
#359
Easy Algorithms

Logger rate limiter

Hash Table Design Data Stream
76.8% acceptance
Mar 31, 2026
1809
198

No description available.

Solution

Rust
Time O(2^n)
Space O(n)
LeetCode
solution.rs
use std::collections::HashMap;

struct Logger {
  map: HashMap<String, i32>,
}

impl Logger {
  fn new() -> Self {
    Logger {
      map: HashMap::new(),
    }
  }

  fn should_print_message(&mut self, timestamp: i32, message: String) -> bool {
    if let Some(&t) = self.map.get(&message) {
      if timestamp < t {
        return false;
      }
    }
    self.map.insert(message, timestamp + 10);
    true
  }
}