Springworks interview question

Merge intervals of array problem