https://school.programmers.co.kr/learn/courses/30/lessons/154539
solution = (numbers) => {
return Array(numbers.length)
.fill(-1)
.reduce((stack, el, idx, arr) => {
while (stack && numbers[stack.at(-1)] < numbers[idx])
arr[stack.pop()] = numbers[idx];
stack.push(idx);
return idx === numbers.length - 1 ? arr : stack;
}, []);
};
'Coding Test > Programmers' 카테고리의 다른 글
[Programmers] (2020 KAKAO BLIND RECRUITMENT) Lv 2. 괄호 변환 (0) | 2023.02.25 |
---|---|
[Programmers] (탐욕법(Greedy)) Lv 2. 큰 수 만들기 (0) | 2023.02.25 |
[Programmers] Lv 2. 124 나라의 숫자 (0) | 2023.02.25 |
[Programmers] (2019 KAKAO BLIND RECRUITMENT) Lv 2. 오픈채팅방 (0) | 2023.02.24 |
[Programmers] (Summer/Winter Coding(~2018)) Lv 2. 스킬트리 (0) | 2023.02.24 |
댓글