def merge_intervals(intervals: List[List[int]]) -> List[List[int]]:
intervals = sorted(intervals)
ans = [intervals[0]]
for start, end in intervals[1:]:
if start <= ans[-1][1]:
ans[-1][1] = max(ans[-1][1], end)
else:
ans.append([start, end])
return ans