TRT
Sign in
easyAdvancedLeetCode#hash-map#stateful-service

Implement a Time-Based Logger Rate Limiter

Track the last accepted timestamp for each message and reason about state growth, ordering, and concurrent requests.

The Runtime Theory Team1 min read
Taught inCache-Conscious Data Structures: Alignment, False Sharing, and Structure of ArraysPro — members onlyStructure C data layouts for CPU cache lines, eliminate multi-core false sharing with explicit alignment, and transform Array of Structures into Structure of Arrays for SIMD saturation.
Solve it

Solving happens on the judge — come back and mark it done

Sample cases

in(1,foo),(2,bar),(3,foo),(8,foo),(11,foo)

outtrue,true,false,false,true

insame message at timestamps 5 and 15

outBoth accepted when the rule requires at least 10 seconds between accepted occurrences

Implement a service that accepts a message only when at least ten seconds have elapsed since the last accepted occurrence of that same message, keeping independent histories per message.

Before you code

Decide how to store the last accepted timestamp per message and confirm that rejected requests leave that timestamp unchanged before handling ordering or growth.

Hints

  1. Keep a map from each message to its last accepted timestamp.
  2. A rejection must not move the timestamp forward, or repeated attempts postpone acceptance forever.
  3. At exactly ten seconds the message is accepted, so compare with greater-or-equal rather than strictly greater.

Production & complexity notes

When solving Implement a Time-Based Logger Rate Limiter on LeetCode (easy), always state your loop or recursion invariant before writing code. Verify how your chosen data structure behaves on degenerate inputs (single-element inputs, all-duplicate keys, strictly monotonic sequences, or maximum constraint sizes up to $10^5$ elements). In production interviews, pair your implementation with an explicit time and auxiliary space complexity proof, explain why alternative brute-force approaches violate the latency budget, and trace how cache locality and memory allocation overhead affect wall-clock throughput on real hardware. Review the step-by-step memory trace in Cache-Conscious Data Structures: Alignment, False Sharing, and Structure of Arrays to reinforce the underlying pattern.

What it practices

Per-key throttle state with last-accepted timestamps and rejection-safe updates, from Turning a key into a slot.

Not started

Sign in to save your learning progress.

Sign in to save