educative.io

Educative

Solution is incorrect

The second step of the problem is to “merge all necessary intervals to produce a list that has only mutually exclusive intervals”.

However the given solution only merges all intervals that overlap or come after the new interval, not those before it in the list.

E.g. The output of insert([[1, 3], [2, 4], [9, 11]], [5, 7]) is [[1, 3], [2, 4], [5, 7], [9, 11]]

In order to fulfill the completion criteria, wouldn’t we have to attempt merge on the modified list of intervals anyways?

This is not a valid input. The problem expects non-overlapping intervals as input. From problem description:

Given a list of non-overlapping intervals…