Sobes.tech
Junior — Senior

Merging overlapping ranges

livecode

Task condition

Given an array of ranges represented by strings like 'a-b', where a and b are integers (with a ≤ b). You need to merge all overlapping or touching ranges and return a new array of ranges sorted in ascending order by start.

Example: ['2-4','7-10','3-5'] => ['2-5','7-10']

Merging overlapping ranges - Live Coding PHP - sobes.tech