#49 Summary Ranges with an Unsorted Array

Companies:
VK Yandex
Themes:
AlgorithmsArraysStringsPractice

An int[] array is given with no repeated elements. Convert this set into a string by collapsing numerically adjacent values 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