Based on my research, I can see that "Real-time Log Analytics" does not appear to be an exact LeetCode problem title. However, LeetCode 635: Design Log Storage System is the most relevant problem that matches the description (tags: Design, Hash Table, Queue, Sliding Window, medium difficulty). This is a classic design problem asked by Adobe and other major tech companies.
Let me create the comprehensive problem document:
Design a log storage system that efficiently stores logs with unique identifiers and timestamps, and supports querying logs within a specified time range at different granularity levels. The system must handle timestamps in a standardized format and retrieve relevant logs based on time-based criteria.
You are given logs where each log contains a unique ID and a timestamp. The timestamp follows the format Year:Month:Day:Hour:Minute:Second (for example, 2017:01:01:23:59:59), where all numeric components are zero-padded decimal numbers.
The core challenge is to implement two operations: storing logs efficiently and retrieving logs whose timestamps fall within a specified range when compared at a given granularity level (Year, Month, Day, Hour, Minute, or Second).
Class: LogSystem
Method 1: put(int id, string timestamp) -> void
id (integer): A unique identifier for the log entry (positive integer)timestamp (string): A timestamp in the format "YYYY:MM:DD:HH:MM:SS" where all components are zero-paddedMethod 2: retrieve(string start, string end, string granularity) -> List<Integer>
start (string): Start timestamp in the same format as stored timestampsend (string): End timestamp in the same format as stored timestampsgranularity (string): One of {"Year", "Month", "Day", "Hour", "Minute", "Second"}, indicating the precision level for comparisonExample 1:
` Input: put(1, "2017:01:01:23:59:59") put(2, "2017:01:01:22:59:59") put(3, "2016:01:01:00:00:00")
retrieve("2016:01:01:01:01:01", "2017:01:01:23:00:00", "Year")
Output: [1, 2, 3]
Explanation: At Year granularity, all three logs fall within the range from 2016 to 2017. Log 1: 2017 (within range) Log 2: 2017 (within range) Log 3: 2016 (within range) All three are returned (order doesn't matter). `
Example 2:
` Input: put(1, "2017:01:01:23:59:59") put(2, "2017:01:01:22:59:59") put(3, "2016:01:01:00:00:00")
retrieve("2016:01:01:01:01:01", "2017:01:01:23:00:00", "Hour")
Output: [1, 2]
Explanation: At Hour granularity, we compare up to the hour level (YYYY:MM:DD:HH). Log 1: "2017:01:01:23" (falls within "2016:01:01:01" to "2017:01:01:23") Log 2: "2017:01:01:22" (falls within "2016:01:01:01" to "2017:01:01:23") Log 3: "2016:01:01:00" (does NOT fall within range; 00 < 01 at the hour level) Returns [1, 2]. `
put() and retrieve() callsgranularity is always one of: "Year", "Month", "Day", "Hour", "Minute", "Second"start timestamp is always less than or equal to end timestampUse a hash table (or list) to store log entries as (id, timestamp) pairs. For retrieval, exploit the fact that string comparison works correctly for timestamps formatted in the specified way—extract the substring of each timestamp up to the granularity level (using predefined indices for each granularity type) and perform string comparisons against the similarly truncated start and end boundaries. The granularity levels map to fixed substring positions: Year (4), Month (7), Day (10), Hour (13), Minute (16), Second (19).