Skip to content

Commit 5531dd6

Browse files
committed
*
1 parent 05660c9 commit 5531dd6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

coding_interviews/algoexpert/merge-overlapping-intervals/merge-overlapping-intervals.js

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* Write a function that takes in a non-empty array of arbitrary intervals,
3+
* merges any overlapping intervals, and returns the new intervals in no
4+
* particular order.
5+
* Each interval interval is an array of two integers, with interval[0] as
6+
* the start of the interval and interval[1] as the end of the interval.
7+
* Note that back-to-back intervals aren't considered to be overlapping.
8+
* For example, [1, 5] and [6, 7] aren't overlapping; however, [1, 6] and
9+
* [6, 7] are indeed overlapping.
10+
* Also note that the start of any particular interval will always be
11+
* less than or equal to the end of that interval.
12+
*
13+
* Input: intervals = [[1, 2], [3, 5], [4, 7], [6, 8], [9, 10]]
14+
* Output: [[1, 2], [3, 8], [9, 10]]
15+
*/
16+
117
// Runtime: O(NlogN), N = array length
218
// Space: O(N)
319

0 commit comments

Comments
 (0)