Function Description Complete the function getMergedintervals in the editor below. getMergedintervals has the following parameter(s): int intervals[[n][2]]: the time intervals Returns intO[2]: the merged intervals in sorted order Constraints 1sns 105 • 1s intervals[ij[2] < 10° • intervals[i][0] s intervals[i][1] for all i. v Input Format For Custom Testing The first line contains an integer, n, size of intervals]. The second line contains the integer 2, the size of intervals[i). Each line i of the n subsequent lines (where 0si

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 7PE
icon
Related questions
Question
How do I make a function for this C++ problem?
Given a collection of time intervals, [start, end], merge and return the
overlapping intervals sorted in ascending order of their start times.
Example
intervals = [[7, 7], [2, 3], [6, 11], [1, 2]]
The interval [1, 2] merges with [2, 3] while [7, 7] merges with [6, 11].
There are no more overlapping intervals. The answer is [[1, 31, [6,
11]].
Function Description
Complete the function getMergedintervals in the editor below.
getMergedIntervals has the following parameter(s):
int intervals[[n][2]]: the time intervals
Returns
intI[2]: the merged intervals in sorted order
Constraints
• 1sns 10
• 1s intervals[i][2]< 10°
intervals[i][0] s intervals[i][1] for all i.
v Input Format For Custom Testing
The first line contains an integer, n, size of intervals[.
The second line contains the integer 2, the size of intervals[i]. Each
line i of the n subsequent lines (where 0si<n) contains two
space-separated integers, the start and end of the interval.
Sarnple Case 0
Transcribed Image Text:Given a collection of time intervals, [start, end], merge and return the overlapping intervals sorted in ascending order of their start times. Example intervals = [[7, 7], [2, 3], [6, 11], [1, 2]] The interval [1, 2] merges with [2, 3] while [7, 7] merges with [6, 11]. There are no more overlapping intervals. The answer is [[1, 31, [6, 11]]. Function Description Complete the function getMergedintervals in the editor below. getMergedIntervals has the following parameter(s): int intervals[[n][2]]: the time intervals Returns intI[2]: the merged intervals in sorted order Constraints • 1sns 10 • 1s intervals[i][2]< 10° intervals[i][0] s intervals[i][1] for all i. v Input Format For Custom Testing The first line contains an integer, n, size of intervals[. The second line contains the integer 2, the size of intervals[i]. Each line i of the n subsequent lines (where 0si<n) contains two space-separated integers, the start and end of the interval. Sarnple Case 0
v Sample Case 0
14
15
Sample Input For Custom Testing
16
17
ŠTDIN
Function
18
19
intervals [] size n = 5
20
intervals[i] size always 2
intervals = [[6, 9], [2, 3], [9, 11], [1,
21
6 9
22
5], [14, 18]]
23 > 1
2 3
9 11
15
14 18
Sample Output
15
6 11
14 18
Explanation
The intervals [2, 3] and [1, 5] merge into [1, 5T, and the intervals [6,
9] and [9, 11] merge into [6, 11]. The merged intervals in sorted
order are [1, 5], [6, 11], [14, 18].
v Sample Case 1
Sample Input For Custom Testing
4 8
2 6
5 7
Sample Output
2 8
Explanation
All three intervals overlap and merge into [2, 8].
Test Resul
Type here to search
Transcribed Image Text:v Sample Case 0 14 15 Sample Input For Custom Testing 16 17 ŠTDIN Function 18 19 intervals [] size n = 5 20 intervals[i] size always 2 intervals = [[6, 9], [2, 3], [9, 11], [1, 21 6 9 22 5], [14, 18]] 23 > 1 2 3 9 11 15 14 18 Sample Output 15 6 11 14 18 Explanation The intervals [2, 3] and [1, 5] merge into [1, 5T, and the intervals [6, 9] and [9, 11] merge into [6, 11]. The merged intervals in sorted order are [1, 5], [6, 11], [14, 18]. v Sample Case 1 Sample Input For Custom Testing 4 8 2 6 5 7 Sample Output 2 8 Explanation All three intervals overlap and merge into [2, 8]. Test Resul Type here to search
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning