Car Pooling algorithm time complexity
The sort is not in the loop, so your algorithm is &quot;just&quot; O(n^2) because the loop dominates, the O(n * log(n)) of the sort is neglegable (for big n).
You can solve the problem in O(n * log(n)) and without sorting or destroying the input.

Walk through the trips and build a Map location =&gt; {liftUps, dropOffs} (O(n) in time, O(n) in memory)

Iterate the map and build an array of {location, liftUps, dropOffs} (O(n) in time, O(n) in memory)

sort the array by location (this is now the slowest part of the algorithm: O(n * log(n)) in time, O(1) in memory)

iterate the array adding liftUps and subtracting dropOffs for each location to an aggregate integer that starts at zero. (O(n) in time, O(1) in memory)

whenever you surpass capacity return false; return true if the loop finishes


const carPooling = (trips, capacity) =&gt; {
    let i = 0;
  const map = new Map();
  for (i = 0; i &lt; trips.length; ++i) {
    const passangers = trips[i][0];
    const start = trips[i][1];
    const end = trips[i][2];
    
    if (map.has(start)) {
        map.set(start, map.get(start) + passangers);
    } else {
        map.set(start, passangers);
    }
    
    if (map.has(end)) {
        map.set(end, map.get(end) - passangers);
    } else {
        map.set(end, -passangers);
    }
  }
  
  const list = new Array(map.size);
  i = 0;
  for (const [location, exchange] of map) {
    list[i++] = {location: location, exchange: exchange}
  }
  
  list.sort((a, b) =&gt; a.location - b.location);
  
  let occupied = 0;
  for (i = 0; i &lt; list.length; ++i) {
    occupied += list[i].exchange;
    if (occupied &gt; capacity) {
        return false;
    }
  }
  
  return true;
}

console.log(carPooling([[2,1,5],[3,3,7]], 4));
console.log(carPooling([[3,2,7],[3,7,9],[8,3,9]], 11));