Given time intervals, find the minimum number of conference rooms required The task is taken from LeetCode


  Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si &lt; ei), find the minimum number of
  conference rooms required.
  
  Example 1:

Input: [[0, 30],[5, 10],[15, 20]]
Output: 2

  
  Example 2:

Input: [[7,10],[2,4]]
Output: 1

  
  NOTE: input types have been changed on April 15, 2019. Please reset to default code definition to get new method signature.


My solution

/**
 * @param {number[][]} intervals
 * @return {number}
 */
var minMeetingRooms = function(intervals) {
  if (intervals.length &lt;= 1) { return intervals.length; }

  const startTimes = [];
  const endTimes = [];
  intervals.forEach(x =&gt; {
    startTimes.push(x[0]);
    endTimes.push(x[1]);
  });
  startTimes.sort((a, b) =&gt; a - b);
  endTimes.sort((a, b) =&gt; a - b);

  let startPointer = 0;
  let endPointer = 0;
  let rooms = 0;
  while(startPointer &lt; intervals.length) {
    if (startTimes[startPointer++] &gt;= endTimes[endPointer]) {
      ++endPointer;
    } else {
      ++rooms    
    }
  }
  return rooms;
};
The code looks much simpler than I would expect for this task. I tried several examples but could neither make it fail, nor did I understand why and how this algorithm works, I was only delighted that it seems to work. Therefore I have only a few remarks.

The early return for length &lt;= 1 is not necessary.

The ++rooms is missing the semicolon.

Apart from that, it looks perfect.