Problem statement

https://binarysearch.com/problems/Contiguous-Intervals/

Solution

Just sort values and then create intervals.

Complexity

It is O(n log n) for time and O(n) for space.

Code

class Solution:
    def solve(self, nums):
        ans = []
        nums = sorted(nums)
        for x in nums:
            if ans and x == ans[-1][-1] + 1:
                ans[-1][-1] += 1
            else:
                ans += [[x, x]]

        return ans