Hints — p99 Design Log Storage System

  1. The timestamp format "YYYY:MM:DD:HH:MM:SS" is fixed-width and zero-padded — so lexicographic string comparison agrees with chronological comparison.

  2. Granularity → prefix length: Year=4, Month=7, Day=10, Hour=13, Minute=16, Second=19. Store in a dict.

  3. On retrieve(start, end, gran), truncate start and end to the prefix length, then for each stored timestamp check start_pref <= ts[:n] <= end_pref.

  4. Inclusive on both ends — use <= not <.

  5. Optimization: store a sorted list and use bisect for O(log n + k) retrieves. For LC’s n ≤ 500, linear scan is fine.

If stuck: see solution.py.