The current implementation is very quadratic but it doesn't need to be. A better algorithm is:
- Keep an ordered list of already used ranges
- Add a function that, given a range, uses binary search to return the index where it should be inserted, or
null if it overlaps with an existing range.
- For a given fix, get the insertion indices for all its changes. If one of them has an overlap, don't apply that fix.
- Add the fix to the list of apliable fixes and all its changes (from last to first) to the list of used ranges.
The current implementation is very quadratic but it doesn't need to be. A better algorithm is:
nullif it overlaps with an existing range.