Design Log Storage System
@dongll Then why not replacing db from list to map too?
I think you're including ':' too for cumulative effect in applying granularity, so Month granularity will simply bey "Year:Month:" while Hour granularity be "Year:Month:Day:Hour:". So ":" is deliberately included for ease in string comparison?
@dreamchase said in Java range query using TreeMap.subMap():
I got this error: error: cannot find symbol: class NavigableMap
No one has replied
the problem states "Given a log's unique id and timestamp". Suppose the timestamp is not unique, you can easily solve that by using id as key.
Same idea, but using stream:
@Aeonaxx The problem states "Unique timestamp", so a map is sufficient.
Most of the top answers take O(N) time for retrieve, where N = number of total logs. It's OK when the data set is small.
But O(number of id in the result) will be significantly faster than O(N) when data set grows larger. Imaging you are trying to get 10 log records out of 10^12 total records.
Another advantage is, by using the Time Hierarchy Trie like structure, it's easy to store the log records in different files/computers without affecting the query efficiency.
Disabled Categories are greyed out
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.