added the code for MergeIntervals with comments