educative.io

https://www.educative.io/courses/grokking-the-coding-interview/3jKlyNMJPEM#

https://www.educative.io/courses/grokking-the-coding-interview/3jKlyNMJPEM#

Why do we have this condition ->

intervals[i].end < newInterval.start

shouldn’t this be better ->

intervals[i].start < newInterval.start

The earlier question on merge intervals also sorts the array by which does make sense, why is the need to compare the end value in this case?

The earlier question on merge intervals has this comparison intervals[i].end < newInterval.start. This assumes that all intervals are sorted (based on first element) and so the only case where there can be an overlap is when first element of interval at index i+1 is lte second element of interval at index i.
They are basically using the same condition (as the previous question) in the second while loop.