Set would also be log(n) where n is avg number of timestamps for a key, because inserting a new key into treeMap requires sorting that key ascendingly among existing keys
@MeetManga2 жыл бұрын
Hi Eric, a tip of the set method when using the treemap solution: public void set(String key, String value, int timestamp) { map.computeIfAbsent(key, k->new TreeMap()).put(timestamp, value); }
@chaitanyasharma62702 жыл бұрын
which solution do you recommend the binary search one or the tree map one
@umangkoul2 жыл бұрын
Binary search is faster but this is simpler and clean