logo CodeStepByStep logo

insertInterval

Language/Type: Java ArrayList collections
Related Links:

Write a method named insertInterval that inserts a new interval into a list of intervals, merging as needed. Your method accepts two parameters: a list of two-element lists of integers representing a set of non-overlapping intervals, sorted by starting number; and a single two-element list representing a new interval to insert. For example, if the list of existing intervals is [[1, 2], [3, 5], [6, 7], [8, 10], [12, 16]] and the new interval to insert is [4, 8], you should return [[1, 2], [3, 10], [12, 16]]. You may assume the input data is valid.

Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.