https://school.programmers.co.kr/learn/courses/30/lessons/42583
function solution(bridge_length, weight, truck_weights) {
if (truck_weights.length === 1) return bridge_length + 1;
var sec = 1;
let status = [];
while (truck_weights.length || status.length) {
let curWeight = 0;
status = status.reduce((acc, t, i) => {
if (i === 0)
++sec;
if (++t.time <= bridge_length) {
acc.push(t);
curWeight += t.weight;
}
return acc;
}, []);
if (curWeight + truck_weights[0] <= weight) status.push({ weight: truck_weights.shift(), time: 1 });
}
return sec;
}
'Coding Test > Programmers' 카테고리의 다른 글
[Programmers] (Summer/Winter Coding(~2018)) Lv 2. 스킬트리 (0) | 2023.02.24 |
---|---|
[Programmers] Lv 2. 2 x N 타일링 (0) | 2023.02.24 |
[Programmers] (정렬) Lv 2. 가장 큰 수 (0) | 2023.02.23 |
[Programmers] (완전탐색) Lv 2. 소수 찾기 (0) | 2023.02.23 |
[Programmers] (완전탐색) Lv 2. 모음사전 (0) | 2023.02.23 |
댓글