본문 바로가기
Coding Test/Programmers

[Programmers] (2021 KAKAO BLIND RECRUITMENT) Lv 2. 메뉴 리뉴얼

by song.ift 2023. 2. 25.

https://school.programmers.co.kr/learn/courses/30/lessons/72411

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

const combination = (idx, start, data, n, str, obj) => {
    if (start === n) {
        const str_tmp = data.join("");
        obj[str_tmp] = ((obj[str_tmp]) || 0) + 1;
        return obj;
    }

    for (let i = idx; i < str.length; ++i) {
        data[start] = str[i];
        obj = combination(i + 1, start + 1, data, n, str, obj);
    }
    return obj;
}

function solution(orders, course) {
    orders = orders.map(el => [...el].sort().join(""));
    return course.reduce((acc, n) => {
        let [pivot, arr] = [0, []];
        const result = orders.reduce((obj, str) => combination(0, 0, [], n, str, obj), {});

        Object.entries(result).forEach(([key, value]) => {
            if (value < 2 || value < pivot) return;
            
            if (value > pivot) {
                pivot = value;
                arr.length = 0;
            }    
            arr.push(key);
        });
        return acc.concat(arr);
    }, []).sort();
}

GitHub : https://github.com/developeSHG/Algorithm-Baekjoon_Programmers/tree/main/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4/lv2/72411.%E2%80%85%EB%A9%94%EB%89%B4%E2%80%85%EB%A6%AC%EB%89%B4%EC%96%BC

 

GitHub - developeSHG/Algorithm-Baekjoon_Programmers: 백준 and 프로그래머스 소스코드

백준 and 프로그래머스 소스코드. Contribute to developeSHG/Algorithm-Baekjoon_Programmers development by creating an account on GitHub.

github.com

 

댓글