Collapse a list of range tuples into the overlapping ranges
问题 I'm looking for the most memory efficient way to solve this problem. I have a list of tuples representing partial string matches in a sentence: [(0, 2), (1, 2), (0, 4), (2,6), (23, 2), (22, 6), (26, 2), (26, 2), (26, 2)] The first value of each tuple is the start position for the match, the second value is the length. The idea is to collapse the list so that only the longest continue string match is reported. In this case it would be: [(0,4), (2,6), (22,6)] I do not want just the longest