Connected interval clusters
Your task
Given an unsorted list of closed integer intervals [start, end], two intervals belong to the same cluster when they overlap or touch at an endpoint, directly, or through a chain of other intervals. Return the number of clusters. Example: [[1,3],[2,4],[7,9],[10,11]] has 3 clusters: {[1,3],[2,4]}, {[7,9]}, and {[10,11]}.
Examples
count_clusters(intervals: list[list[int]]) -> intExample 1
Input
count_clusters([[1, 3], [2, 4], [7, 9], [10, 11]])Output
3