Skip to content

Commit

Permalink
09.30: queue(카페 확장)
Browse files Browse the repository at this point in the history
  • Loading branch information
luckylooky2 committed Oct 1, 2024
1 parent e157f75 commit b90228a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions programmers/카페 확장.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 카페 확장 : 큐
function solution(menu, order, k) {
var answer = 0;
let time = 0;
const q = [];
let idx = 0;

for (const o of order) {
const makingTime = menu[o];
while (time >= q[idx]) {
idx++;
}
if (idx < q.length) {
q.push(q[q.length - 1] + makingTime);
} else {
q.push(time + makingTime);
}
answer = Math.max(answer, q.length - idx);
time += k;
}
return answer;
}

0 comments on commit b90228a

Please sign in to comment.