Store logs by timestamp and retrieve them by year, month, day, hour, minute or second
Problem
Logs, analytics events and audit trails are usually queried by time range at a chosen precision: "everything on 1 Jan", "everything between 9 and 10 o'clock". Build LogStore:
const store = new LogStore();
store.put(1, "2017:01:01:23:59:59");
store.put(2, "2017:01:01:22:59:59");
store.put(3, "2016:01:01:00:00:00");
store.retrieve("2016:01:01:01:01:01", "2017:01:01:23:00:00", "Year"); // [3, 2, 1]
store.retrieve("2016:01:01:01:01:01", "2017:01:01:23:00:00", "Hour"); // [2, 1]Ref. UR-1429 · © UIRound · uiround.com/questions/store-logs-by-timestamp-and-retrieve-them-by-year-month-day-hour-minute-or-second
Unlock this question
The full problem, its tests and the tested solution are part of Pro.
- 2
- code listings
- 5
- edge cases
What's inside
- The full problem, with examples
- Tests that check your solution
- Step-by-step
- Approach
- Solution
- Complexity
- Edge cases
- Follow-up questions
- Card worldwide
- UPI and net banking in India
- One-time payment, nothing renews
Stuck? Take a hint
- 1Timestamps like '2017:01:01:23:59:59' have fixed-width, zero-padded fields from largest to smallest, so comparing them as strings compares them as times.
Try it in the editor
Run your code as often as you like. Submitting it to the full test suite is part of Pro.
Private, and saved in this browser as you type. All your notes are on My lists.