ranges based on their starting points.end to keep track of the end of the last merged interval, starting with -1.ranges.
end + 1, an uncovered range is found; add it to the result.end to be the maximum of the current end and the end of the current range.end is less than n - 1, add the range from end + 1 to n - 1 to the result as the last uncovered range.