logo CodeStepByStep logo

summaryRanges

Language/Type: Java ArrayList collections
Related Links:

Write a method named summaryRanges that accepts as a parameter an ArrayList of integers and returns the smallest sorted list of ranges that cover all numbers in the list exactly. That is, each element of the array is covered by exactly one of the ranges, and there is no integer contained in a range but not in the original list.

Return ranges as strings of the form "a->b" for a < b, or "a" for a single number.

For example, if the list passed is [0, 1, 2, 4, 5, 7], you should return ["0->2", "4->5", "7"].

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.