You are given a list of non-overlapping intervals, intervals, representing covered segments within a larger overall range [minVal, maxVal]. These intervals are sorted by their start times.
Your task is to invert this list of intervals by finding all the gaps (uncovered segments) between them, within the [minVal, maxVal] range.
The output should be a list of intervals representing these gaps, also sorted and non-overlapping.
intervals = [ [1, 3], [5, 7] ]
minVal = 0
maxVal = 10
[ [0, 1], [3, 5], [7, 10] ]
Gaps are before the first interval, between the intervals, and after the last interval within the given range.
intervals = [ [0, 10] ]
minVal = 0
maxVal = 10
[ ]
The intervals completely cover the entire range [0, 10], leaving no gaps.
intervals = [ ]
minVal = 0
maxVal = 5
[ [0, 5] ]
With no intervals provided, the entire [0, 5] range is considered a single gap.
intervals = [ [1, 3], [5, 7] ]
minVal = 0
maxVal = 10
[ [0, 1], [3, 5], [7, 10] ]