Merge overlapping intervals | Atlassian Interview Question