I have a list of elements where each element is a non-negative integer. I want to filter the list so that only the largest unclosed ranges stand out. And I want to do this with O(n) with one loop. This list will always be sorted according to the starting integer for each range. A limited range element may occur before or after an environment element in a list.
Example:
Suppose I have a list of {[0-12],[5-15],[5-20],[10-20],[11-30],[25-42],[28-40]} . In this list, ranges [5-15] and [10-20] fall into the range [5-20] , so I need to drop them. Similarly, a range element [28-40] discarded when it falls into a range [25-42] . I want to do this filtering using a single loop to achieve O(n) time complexity.
Is it possible to achieve this? If not, then a better way to make filtering more complicated than O(n) . A Java solution would be great.
source share