A set of real numbers can be represented as the union of several disjoint intervals, where each interval is in the form [a, b). A real number x is in the set if one of its intervals [a, b) contains x (i.e. a <= x < b).You are given a sorted list of disjoint intervals intervals representing a set of real numbers as described above, where intervals[i] = [ai, bi] represents the interval [ai, bi). You are also given another interval toBeRemoved.Return the set of real numbers with the intervaltoBeRemovedremoved from* intervals*. In other words, return the set of real numbers such that every x in the set is in intervals but not in toBeRemoved. Your answer should be a sorted list of disjoint intervals as described above.
class Solution: # Time: O(n) # Space: O(1) extra (output excluded) def remove_interval( self, intervals: list[list[int]], to_be_removed: list[int] ) -> list[list[int]]: start, end = to_be_removed result: list[list[int]] = [] for a, b in intervals: if a >= end or b <= start: result.append([a, b]) continue if a < start: result.append([a, start]) if b > end: result.append([end, b]) return result