10635. Design Log Storage System

You are given a collection of log entries, where each entry consists of a unique id and a timestamp. The timestamp is a string in the format Year:Month:Day:Hour:Minute:Second (for example, 2018:07:14:09:21:00). All fields are zero-padded numbers.

Design a logging system with the following methods:

  • void addLog(int logId, String time): Stores a log identified by logId and its time in the system.
  • List<Integer> getLogs(String startTime, String endTime, String granularity): Returns the list of logIds sorted in ascending order whose timestamps are in the range from startTime to endTime (inclusive), considering only up to the specified granularity ("Year", "Month", "Day", "Hour", "Minute", or "Second").

Examples

addLog(11, "2018:07:14:09:21:00");
addLog(22, "2018:07:14:08:59:00");
addLog(33, "2017:06:01:12:00:00");
getLogs("2017:01:01:00:00:00", "2018:12:31:23:59:59", "Year");   // returns [11,22,33]
getLogs("2018:07:14:00:00:00", "2018:07:14:09:00:00", "Hour");   // returns [22]

Constraints

  • No more than 350 addLog or getLogs operations will be made.
  • Year is in the range [2001, 2019]. Hour is in the range [00, 23].
  • The returned list from getLogs is sorted in ascending order.




Please use Laptop/Desktop or any other large screen to add/edit code.