https://school.programmers.co.kr/learn/courses/30/lessons/132265
function solution(topping) {
const [lDic, lSizeArr, rDic, rSizeArr] = [new Set(), [], new Set(), []];
topping.forEach((el, idx) => {
lDic.add(el);
if (idx !== 0) rDic.add(topping.at(-idx));
lSizeArr.push(lDic.size);
rSizeArr.push(rDic.size);
});
return lSizeArr.reduce((acc, el, idx) => (el === rSizeArr.at(-idx - 1)) ? ++acc : acc, 0);
}
'Coding Test > Programmers' 카테고리의 다른 글
[Programmers] (Summer/Winter Coding(~2018)) Lv 2. 방문 길이 (0) | 2023.03.03 |
---|---|
[Programmers] (2018 KAKAO BLIND RECRUITMENT) Lv 2. [3차] 파일명 정렬 (0) | 2023.03.03 |
[Programmers] (2021 KAKAO BLIND RECRUITMENT) Lv 2. 메뉴 리뉴얼 (0) | 2023.02.25 |
[Programmers] (깊이/너비 우선 탐색(DFS/BFS)) Lv 2. 게임 맵 최단거리 (0) | 2023.02.25 |
[Programmers] (2020 KAKAO BLIND RECRUITMENT) Lv 2. 괄호 변환 (0) | 2023.02.25 |
댓글