To check if starting point of next range is lying between the previous range and ending point of next range is greater than the Ending point of previous range then update ending point of previous range by ending point of next range .
prev = merged [ - 1 ] NEW_LINE curr = arr [ i ] NEW_LINE if curr . s >= prev . s and curr . s <= prev . e and curr . e > prev . e : NEW_LINE INDENT merged [ - 1 ] . e = curr . e NEW_LINE DEDENT else : NEW_LINE