Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Question about specific scenario

raphael_1st

Jul 26, 2024

Hello,

I have a question about this algorithm when we have merging intervals that come before the newly inserted interval (passing the redundancy). For example, if we have,

input = [[1,3], [2,4],[7,9],[8,12]], new interval = [6, 10]

the result should be,

[[1,4], [6,12]]

I can't understand, with the current algorithm in this example, how we get the [1,4]. If I understood correctly, because we are not merging the intervals that come before the new insertion, the interval will be instead [2,4].

In other words, the final result will be,

[[2,4], [6,12]], instead of [[1,4], [6,12]].

Is this example valid or am I missing something?

0

0

Comments
Comments

On this page