Maximum Time Range
Collapse Content
Show Content
You're only able to stay in the hotel if an event is running. Can you find and print the maximum time ranges that you can stay in the hotel?
In this challenge, instead of avoiding overlapping times, you want them!
See if you can find an O(n log n) solution.
I/O Format
The input is the same as the last challenge. Find the optimal range of times of events and print each rnage like this: [start , end]
.
Sample Input
1 8 10 18 4 6 14 16 5 8
Sample Output
[4, 8] [10, 18]
Explanation
You are given 4 events:
[10,18] [4,6] [14,16] [5,8]
[4,8] [10,18]
is the maximum time ranges within those times.
Time 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20... Events aaaaaaa cccccccccccccccccccccccc bbbbbbbbbb ddddddd Max. ------------- ------------------------
Challenge
Print out the maximum ranges.
Please sign in or sign up to submit answers.
Alternatively, you can try out Learneroo before signing up.