DIY: Find Interval Sets

Solve the interview question "Find Interval Sets" in this lesson.

Problem statement

You are given a list of intervals, and you have to organize them into sets such that only one interval can occupy a set at a time. Your job is to find the minimum number of sets we need to process all the intervals.

Input

The input is a list of lists. The nested lists contain two integers representing the starting and ending points of the interval. The following is an example of input:

{{1, 4}, {2, 5}, {4, 8}, {5, 6}, {5, 8}, {6, 7}}

Output

The output is an integer representing the number of sets needed to process the intervals. The following is an example output:

3

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.