Merge overlapping and adjacent ranges | Amazon Interview Question