Hints — p99 Design Log Storage System
-
The timestamp format
"YYYY:MM:DD:HH:MM:SS"is fixed-width and zero-padded — so lexicographic string comparison agrees with chronological comparison. -
Granularity → prefix length: Year=4, Month=7, Day=10, Hour=13, Minute=16, Second=19. Store in a dict.
-
On
retrieve(start, end, gran), truncatestartandendto the prefix length, then for each stored timestamp checkstart_pref <= ts[:n] <= end_pref. -
Inclusive on both ends — use
<=not<. -
Optimization: store a sorted list and use
bisectfor O(log n + k) retrieves. For LC’s n ≤ 500, linear scan is fine.
If stuck: see solution.py.