#331 Summary Ranges with Sorting

Companies:
VK
Themes:
AlgorithmsArraysStringsPractice

A list of integers is given. The values are only positive numbers and zero, with no duplicate elements. Convert this set into a string by collapsing consecutive numbers into ranges:

// Examples:
// [1,4,5,2,3,9,8,11,0] => "0-5,8-9,11"
// [1,4,3,2] => "1-4"
// [1,4] => "1,4"

public String compress(int[] array) {
 ...
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in