Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
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 Image

0

0

Comments
Comments
M
Mikhail Putilov3 years ago

Sorry for the grammatical typos. I can't find how to edit my own comments

Design Gurus
Design Gurus3 years ago

Will the solution be better than O(N*logN)?

M
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).

M
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