0% completed
I think the article misses an obvious discussion about TreeMap. The challange ca...
Mikhail Putilov
Jan 5, 2023
I think the article misses an obvious discussion about TreeMap. The challange can be solved efficiently with a TreeMap because of it TreeMap#ceilingEntry method that works O(log N) time. Every interval is uniquely identified by its starting point. Filing in the map with intervals and then querying it for a next entry seems like an obvious choice for me.
It beat 80% of solutions on leetcode: https://pastebin.com/r1bc0EwT

0
0
Comments
Mikhail Putilov3 years ago
Sorry for the grammatical typos. I can't find how to edit my own comments
Design Gurus3 years ago
Will the solution be better than O(N*logN)?
Mikhail Putilov3 years ago
Ofc no I wanted to point out that the solution with TreeMap requires less explanations, easier to code and has less places where someone can accidentally write wrong conditional (during an interview process, for example).
Mikhail Putilov3 years ago
I have just plugged the solution from the article and it was much slower (beats 20% of all solutions). I really doubt that the solution is a good one. It is good for training though
On this page