Please use Laptop/Desktop or any other large screen for the Mock Interview Session.

Design Log Storage System



YouTube Video Thumbnail
Link

Watch above sample mock interview video to see how it works.
Login and Buy Premium to Start the Interview



Log Storage System Design

Log Storage System Design

Problem Statement

You have several logs, each with a unique identifier and a timestamp. The timestamp is formatted as YYYY:MM:DD:HH:MM:SS, such as 2018:02:15:14:30:45. All components are zero-padded numbers.

Design a system to store logs and support the following operations:

void addLog(int logId, string timeStamp): Store a log entry with the given unique ID and timestamp.

List<int> fetchLogs(String startTime, String endTime, String level): Return all log IDs whose timestamps fall within the range from startTime to endTime, inclusive. The level parameter indicates the granularity of the timestamp to consider (e.g., "Year", "Month", "Day", "Hour", "Minute", or "Second"). For example, if startTime = "2018:02:15:14:00:00", endTime = "2018:02:16:16:00:00", and level = "Day", then logs from February 15 and February 16 of 2018 should be included.

Examples

addLog(10, "2018:03:01:12:00:00");
addLog(20, "2018:03:01:11:30:00");
addLog(30, "2017:12:31:23:59:59");
fetchLogs("2017:12:31:00:00:00", "2018:03:01:12:00:00", "Year"); 
// Expected output: [10, 20, 30] because logs are within 2017 and 2018.

fetchLogs("2017:12:31:00:00:00", "2018:03:01:12:00:00", "Hour"); 
// Expected output: [10, 20] because only logs from 2018:03:01:11 and 2018:03:01:12 are included; log 30 is outside the hour range.

Constraints

  • At most 350 calls will be made to addLog and fetchLogs.
  • The year component is between 2010 and 2020.
  • The hour component ranges from 00 to 23.
  • The order of log IDs in the returned list does not matter.