Time Scheduler


Collapse Content

You're working on a scheduler app. The user would like to attend as many events as possible but cannot attend events that overlap. Can you find the schedule with the greatest number of non-overlapping events?

See if you can find an O(n log n) solution.

I/O Format

You will be given a list of n numbers. The numbers consist of n/2 pairs, where each pair is the start and end time of an event. Find the optimal schedule of events and print each time like this: [start , end].

Sample Input

1
8
4 8 1 3 7 9 5 6

Sample Output

[1,3] [5,6] [7,9]

Explanation
You are given 4 events:

[4,8] [1,3] [7,9] [5,6]

[4,8] overlaps with 2 other events, so it should be left out, but the other 3 can all be included.

Challenge

Print out the schedule that fits the most events.

Please sign in or sign up to submit answers.

Alternatively, you can try out Learneroo before signing up.

Comments

  • If you're looking for code to get started, this Java code converts the input into Tuples, and added a helpful compareTo method to the Tuples.

Contact Us
Sign in or email us at [email protected]