398. Repeated Student Roll Number
Combine Road Repair Zones

A road is represented as a single continuous line. Every position on the road is identified by an integer marker.

A maintenance team receives several road sections that need repair. Each section includes every position from its starting marker through its ending marker.

Combine all repair sections that overlap or touch each other. Return the resulting separate repair zones.

Method Signature

List<String> combineRepairZones(List<String> repairZones)

Parameters

  • repairZones: The sections that need repair.
  • Each section is formatted as "startMarker,endMarker".

Returns

The combined repair zones, formatted as "startMarker,endMarker".

Return the zones in ascending order of their starting markers.

Constraints

  • 1 ≤ repairZones.size() ≤ 10,000
  • Each entry in repairZones is formatted as "startMarker,endMarker".
  • 0 ≤ startMarker ≤ endMarker ≤ 1,000,000
  • The repair sections may be given in any order.
  • repairZones is never null and never contains null values.

Examples

Example 1

combineRepairZones( repairZones = List.of("30,38", "7,12", "10,18", "50,55"))

Returns List.of("7,18", "30,38", "50,55").

The sections "7,12" and "10,18" overlap, so they become the single repair zone "7,18".

Example 2

combineRepairZones( repairZones = List.of("4,9", "9,14", "20,24"))

Returns List.of("4,14", "20,24").

The first two sections touch at marker 9, so they form one continuous repair zone.

Example 3

combineRepairZones( repairZones = List.of( "40,45", "6,11", "8,16", "15,22", "21,28", "60,63"))

Returns List.of("6,28", "40,45", "60,63").

The four connected sections from marker 6 through marker 28 are combined into one repair zone.



Please use Laptop/Desktop or any other large screen to add/edit code.