Skip to content

Instantly share code, notes, and snippets.

@joncloud
Created August 29, 2016 04:03
Show Gist options
  • Save joncloud/db5c9663ecdd3802878e3f08089e4a1f to your computer and use it in GitHub Desktop.
Save joncloud/db5c9663ecdd3802878e3f08089e4a1f to your computer and use it in GitHub Desktop.

Zombit antidote

Forget flu season. Zombie rabbits have broken loose and are terrorizing Silicon Valley residents! Luckily, you've managed to steal a zombie antidote and set up a makeshift rabbit rescue station. Anyone who catches a zombie rabbit can schedule a meeting at your station to have it injected with the antidote, turning it back from a zombit to a fluffy bunny. Unfortunately, you have a limited amount of time each day, so you need to maximize these meetings. Every morning, you get a list of requested injection meetings, and you have to decide which to attend fully. If you go to an injection meeting, you will join it exactly at the start of the meeting, and only leave exactly at the end.

Can you optimize your meeting schedule? The world needs your help!

Write a method called answer(meetings) which, given a list of meeting requests, returns the maximum number of non-overlapping meetings that can be scheduled. If the start time of one meeting is the same as the end time of another, they are not considered overlapping.

meetings will be a list of lists. Each element of the meetings list will be a two element list denoting a meeting request. The first element of that list will be the start time and the second element will be the end time of that meeting request.

All the start and end times will be non-negative integers, no larger than 1000000. The start time of a meeting will always be less than the end time.

The number of meetings will be at least 1 and will be no larger than 100. The list of meetings will not necessarily be ordered in any particular fashion.

Languages

To provide a Python solution, edit solution.py To provide a Java solution, edit solution.java

Test cases

Inputs: (int) meetings = [[0, 1], [1, 2], [2, 3], [3, 5], [4, 5]] Output: (int) 4

Inputs: (int) meetings = [[0, 1000000], [42, 43], [0, 1000000], [42, 43]] Output: (int) 1

Use verify [file] to test your solution and see how it does. When you are finished editing your code, use submit [file] to submit your answer. If your solution passes the test cases, it will be removed from your home folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment