title: Schedule Optimization in Python for lists of lists [interval scheduling]
body: <p>Doing some learning problems in python and I've come across a challenge that I'm having trouble working out.</p>
  
  <p><strong>Reqs</strong></p>
  
  <ul>
  <li><p>I have a list of lists, where the first and last items are respectively the start and end times of a meeting. </p></li>
  <li><p>a 'possible meeting' is one where the start and end times of meeting 1 and 2 can be the same or where 1 &lt; 2, but they can't overlap. So in:
  <code>[[0,1][1,2][2,3],[2,5]]</code> there are 3 possible meetings because the 1st, 2nd, and 3rd meetings can all happen sequentially, but the last can't -- or at least if the last can happen the 3rd one can't.</p></li>
  <li><p>I need to return the number of possible meetings</p></li>
  <li><p>w/o any sort of special knowledge of an appropriate algorithm that would work well here (still learning), my approach has been to sort the lists of lists and compare them to the next one to see if a meeting is possible. All given sets for the problem have at least 1 meeting that can occur (since at least one meeting would necessarily be possible).</p></li>
  </ul>
  
  <p>Here's what I have so far in python3.4:</p>
  
  <pre><code>def answer(meetings):
      index = 0
      nextIndex = index + 1
      possibleMeetings = 1
      impossibleMeetings = 0
      sortedMeetings = sorted(meetings)
  
      for item in sortedMeetings:
          firstItem = item[1]
          secondItem = sortedMeetings[nextIndex][0]
  
          if firstItem &lt;= secondItem:
               possibleMeetings +=1
               nextIndex+=1
           elif firstItem &gt; secondItem:
               impossibleMeetings +=1
               nextIndex+=1
          if nextIndex == len(sortedMeetings):
              break
      index +=1
  return possibleMeetings, impossibleMeetings
  </code></pre>
  
  <p>Problems:</p>
  
  <ul>
  <li><p>I have the feeling that this is a brute-force way to sort things and compare them</p></li>
  <li><p>I don't think it will scale well</p></li>
  <li><p>There are likely cases that will break it</p></li>
  </ul>
  
  <p>Any help here would be greatly appreciated! Hoping to expand my conception of what's possible in this sort of problem. Thanks!</p>