Merge Intervals, is a LeetCode problem from sorting subdomain. This problem has also been asked in companies like Google,Facebook,Linkedin during the interview. In this post we will see how we can solve this challenge in Swift

Problem Description

You can find the full details of the problem Merge Intervals at LeetCode

Solution

Time Complexity: O(nlogn), Space Complexity: O(n)

Definition for an interval.

public class Interval {

public var start: Int

public var end: Int

public init(_ start: Int, _ end: Int) {

self.start = start

self.end = end

}

}

Please check the main.swift snippet for the solution.

This solution originally posted at: Github by @soapyigu