
16. Functional improvement
Sunhyup Lee. (2024). To be a successful candidate for the coding test. goldenrabbit. p.210.
Problem solving
1. Queue를 이용하여 풀기

Queue solving
Jay Tak
function solution(progresses, speeds) {
const answer = [];
const n = progresses.length;
// ① 각 작업의 배포 가능일 계산
const daysLeft = progresses.map((progress, index) => Math.ceil((100 - progress))/speeds[index]);
let count = 0;
// ② 배포될 작업의 수 카운트
let maxDay = daysLeft[0];
// ③ 현재 배포될 작업 중 가장 늦게 배포될 작업의 가능일
for (let i = 0; i < n; i++) {
if (daysLeft[i] <= maxDay) {
// ④ 현재 배포될 작업이 가장 늦게 배포될 작업의 가능일보다 빠른경우
count++;
} else {
// ⑤ 현재 배포 가능일이 가장 늦은 배포일보다 느리면, 기존의 카운드 모두 push하고 새롭게 1로 재할당
answer.push(count);
count = 1;
maxDay = daysLeft[i];
}
}
answer.push(count);
// ⑥ 마지막 카운트 된 작업들 함께 push
return answer;
}