title: Maximum number of meetings that we can conduct
body: <p>This was asked during an interview to calculate the maximum number of meetings that can be held based on given 2 arrays.</p>
  
  <p>Size of arrays is from 1 to 50, and the values in the array are from 1 to 1000 max.</p>
  
  <p>I have an array that represents starting time for meetings - [1,3,3,5,7].
  Another array that represents the time taken for the above meeting - [2,2,1,2,1]</p>
  
  <p>As per the above data, the first meeting starts at 1 and continues for 2hrs. so it covers from 1hr to 3hrs as meeting duration is 2hrs.
  The second and third meeting starts at 3 and they continue for 2hrs or 1hrs. so they cover 3 to 5 for 2nd meeting, 3 to 4 for the third meeting.
  The fourth meething starts at 5 and continues for 2hrs. So it covers 5 to 7 as duration is 2hrs
  The last meeting starts at 7 and continues for 1hr.</p>
  
  <p>The second and third are occurring at same time, so we just need to pick only one such that we can arrange maximum number of meetings.</p>
  
  <p>For the given above sample data we can arrange 4 meetings.</p>
  
  <p>Another example:</p>
  
  <p>starting time for meetings - [1,3,5].
  Time taken for meetings - [2,2,2].</p>
  
  <p>Here none of the meetings can conflict so maximum we can arrange 3 meetings.</p>
  
  <p>This is the code I came up with:</p>
  
  <pre><code>public static int getMaximumMeetings(List&lt;Integer&gt; start, List&lt;Integer&gt; timeTaken) {
      // Map with key as meeting start time, and value as the list of time taken values.
      Map&lt;Integer, List&lt;Integer&gt;&gt; map = new LinkedHashMap&lt;&gt;();
      for (int i = 0; i &lt; start.size(); i++) {
          List&lt;Integer&gt; list = map.get(start.get(i));
          if (list == null) {
              list = new ArrayList&lt;&gt;();
          }
          list.add(timeTaken.get(i));
          map.put(start.get(i), list);
      }
      System.out.println(map);
  
      // Get meetings one by one
      Set&lt;Integer&gt; keys = map.keySet();
      Iterator&lt;Integer&gt; it = keys.iterator();
      Integer time = it.next();
      List&lt;Integer&gt; list = map.get(time);
      // Sort the time taken values so we can pick the least duration meeting
      list.sort(null);
      int count = 1;
  
      while (it.hasNext()) {
          List&lt;Integer&gt; prevList = list;
          int value = prevList.get(0);
          int prevTime = time;
  
          time = it.next();
          list = map.get(time);
          list.sort(null);
      // Check if total time taken for this meeting is less than the next meeting starting time.
          if (value + prevTime &lt;= time) {
              count++;
          } else {
              time = prevTime;
              list = prevList;
          }
      }
      return count;
  }
  </code></pre>
  
  <p>This program has cleared only 5 test cases out of 12, remaining all failed. All the test cases are hidden. So I was not clear what is wrong with this code.</p>