We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
this can be solved in O(nlogn) with greedy algo. Sort all the end points, then iterate through all the end points using a simple array of size 2 to keep track of the intervals that are still open(haven't met their closing point yet). Whenever the opening intervals reached 3, just remove the interval that spans the furtherst.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Interval Selection
You are viewing a single comment's thread. Return to all comments →
this can be solved in O(nlogn) with greedy algo. Sort all the end points, then iterate through all the end points using a simple array of size 2 to keep track of the intervals that are still open(haven't met their closing point yet). Whenever the opening intervals reached 3, just remove the interval that spans the furtherst.