https://school.programmers.co.kr/learn/courses/30/lessons/131127
const solution = (want, number, discount) => {
return discount.reduce(
(acc, el) => {
if (acc.queue.length >= 10) var shifted = acc.queue.shift();
acc.queue.push(el);
if (want.some((e) => e === shifted)) ++number[want.indexOf(shifted)];
if (want.some((e) => e === el)) --number[want.indexOf(el)];
acc.res += number.every((e) => e <= 0) ? 1 : 0;
return acc;
},
{ queue: [], res: 0 }
).res;
};
'Coding Test > Programmers' 카테고리의 다른 글
[Programmers] (2022 KAKAO BLIND RECRUITMENT) Lv 2. 주차 요금 계산 (0) | 2023.02.22 |
---|---|
[Programmers] (2018 KAKAO BLIND RECRUITMENT) Lv 2. [3차] n진수 게임 (0) | 2023.02.22 |
[Programmers] Lv 2. 땅따먹기 (0) | 2023.02.18 |
[Programmers] (2018 KAKAO BLIND RECRUITMENT) Lv 2. [3차] 압축 (0) | 2023.02.17 |
[Programmers] (2022 KAKAO BLIND RECRUITMENT) Lv 2. k진수에서 소수 개수 구하기 (0) | 2023.02.16 |
댓글