I have different time intervals (contains partial or full overlaps). I provided the sample input and output so that it would be easy to understand.
Sample Input-1:
[1-5, 2-3, 3-5, 3-5, 3-6]
Sample Output-1:
[(1-2):1, (2-3):2, (3-5):4, (5-6):1]
The above output informs that, for the interval (1-2), there is only one interval (among given inputs) that overlaps. for the interval (2-3), both inputs 1-5 and 2-3 overlap. and so on.
I did a search and found that an interval tree (with slight modifications) could be the best match to store and produce this output. I am here to hear the other's opinion on which could be the more suitable data structure for my use case.
PS:
I don't wish to update/read/delete
the tree. Just insert the interval and flat that tree similar to the sample output.
Sample Input-2:
[1-2, 3-4, 5-6]
Sample Output-2:
[(1-2):1, (3-4):1, (5-6):1]
Sample Input-3:
[1-3, 3-4, 5-6]
Sample Output-3:
[(1-3):1, (3-4):1, (5-6):1]
Sample Input-4:
[1-4, 3-4, 5-6]
Sample Output-4:
[(1-2):1, (3-4):2, (5-6):1]