Skip to content

Commit

Permalink
Time: 258 ms (65.43%) | Memory: 84.2 MB (56.79%) - LeetSync
Browse files Browse the repository at this point in the history
  • Loading branch information
ShatilKhan committed Feb 18, 2024
1 parent 734337f commit 73cb9a4
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions 2479-meeting-rooms-iii/meeting-rooms-iii.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* @param {number} n
* @param {number[][]} meetings
* @return {number}
*/
var mostBooked = function(n, meetings) {
let solution = new Solution();
return solution.mostBooked(n, meetings);
};

class Solution {
mostBooked(n, meetings) {
const ans = new Array(n).fill(0);
const times = new Array(n).fill(0);
meetings.sort((a, b) => a[0] - b[0]);

for (let i = 0; i < meetings.length; i++) {
const [start, end] = meetings[i];
let flag = false;
let minind = -1;
let val = Number.MAX_SAFE_INTEGER;
for (let j = 0; j < n; j++) {
if (times[j] < val) {
val = times[j];
minind = j;
}
if (times[j] <= start) {
flag = true;
ans[j]++;
times[j] = end;
break;
}
}
if (!flag) {
ans[minind]++;
times[minind] += (end - start);
}
}

let maxi = -1;
let id = -1;
for (let i = 0; i < n; i++) {
if (ans[i] > maxi) {
maxi = ans[i];
id = i;
}
}
return id;
}
}

0 comments on commit 73cb9a4

Please sign in to comment.