meeting room

by Krishna Ananthi

JavaScript

function     canAttendMeetings(intervals) {
        intervals.sort((a,b)=>a[0]-b[0]);
        let prevEnd = intervals[0][1];
        for(let i=1;i<intervals.length;i++){
            const [start,end] = intervals[i];        
            if(start < prevEnd)
            	return false;
            else
                prevEnd = end;
        }
        return true;
    }
    
   // console.log(canAttendMeetings([[0,30],[5,10],[15,20]]));
   class Interval {
   constructor(start, end) {
      this.start = start;
      this.end = end;
    }
  }
   function    minMeetingRooms(intervals) {
        const time = [];
        for (const i of intervals) {
            time.push([i.start, 1]);
            time.push([i.end, -1]);
        }
        console.log(time)
        time.sort((a, b) => a[0] === b[0] ? a[1] - b[1] : a[0] - b[0]);
        
        console.log(time)
        let res = 0, count = 0;
        for (const t of time) {
            count += t[1];
            res = Math.max(res, count);
        }
        return res;
    }
    
    console.log(minMeetingRooms([new Interval(0,40),new Interval(5,10),new Interval(3,5)]))