문제 https://school.programmers.co.kr/learn/courses/30/lessons/43164# 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이 주어진 항공권을 모두 이용해 여행경로를 짤 때, 방문하는 공항 경로를 구하는 문제이다. 이때 주의할 점은 가능한 경로가 여러 개 있다면, 알파벳 순서가 앞서는 경로를 반환해야 한다는 것이다. 이 조건을 만족하기 위해 tickets 배열을 먼저 정렬해준다. 자바스크립트 sort는 기본적으로 알파벳 오름차순 순서로 배열을 해주고, 2차원 배열의 경우 첫 번째 요소가 같은 경우, 두 번째 ..
문제: 최소직사각형 https://school.programmers.co.kr/learn/courses/30/lessons/86491?language=javascript 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이 function solution(sizes) { // 가로, 세로 중 작은 값(세로)/큰 값(가로) 구분해서 각각의 최댓값을 곱한 값 sizes.map(size => size.sort((a, b) => a - b)) let maxH = 0 let maxW = 0 for (let [h, w] of sizes) { maxH = Math.ma..
문제 https://www.acmicpc.net/problem/14501 14501번: 퇴사 첫째 줄에 백준이가 얻을 수 있는 최대 이익을 출력한다. www.acmicpc.net 풀이 const fs = require("fs"); const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt"; let [num, ...arr] = fs.readFileSync(filePath).toString().trim().split("\n"); const n = +num; const schedule = arr.map((row) => row.split(" ").map(Number)); let maxVal = Number.MIN_SAFE_INTEGE..
문제 https://www.acmicpc.net/problem/16439 16439번: 치킨치킨치킨 첫 번째 줄에 고리 회원의 수 N (1 ≤ N ≤ 30) 과 치킨 종류의 수 M (3 ≤ M ≤ 30) 이 주어집니다. 두 번째 줄부터 N개의 줄에 각 회원의 치킨 선호도가 주어집니다. i+1번째 줄에는 i번째 회원의 선 www.acmicpc.net 풀이 const fs = require("fs"); const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt"; let [n, ...arr] = fs.readFileSync(filePath).toString().trim().split("\n"); const [N, M] = n.spl..
문제 https://www.acmicpc.net/problem/2503 2503번: 숫자 야구 첫째 줄에는 민혁이가 영수에게 몇 번이나 질문을 했는지를 나타내는 1 이상 100 이하의 자연수 N이 주어진다. 이어지는 N개의 줄에는 각 줄마다 민혁이가 질문한 세 자리 수와 영수가 답한 스트 www.acmicpc.net 풀이 const fs = require("fs"); const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt"; let [n, ...arr] = fs.readFileSync(filePath).toString().trim().split("\n"); const N = +n; const response = arr.map..
문제 https://www.acmicpc.net/problem/1969 1969번: DNA DNA란 어떤 유전물질을 구성하는 분자이다. 이 DNA는 서로 다른 4가지의 뉴클레오티드로 이루어져 있다(Adenine, Thymine, Guanine, Cytosine). 우리는 어떤 DNA의 물질을 표현할 때, 이 DNA를 이루는 뉴클레오 www.acmicpc.net 풀이 const fs = require("fs"); const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt"; let [n, ...arr] = fs.readFileSync(filePath).toString().trim().split("\n"); const [N, M] ..
문제 https://www.acmicpc.net/problem/2164 2164번: 카드2 N장의 카드가 있다. 각각의 카드는 차례로 1부터 N까지의 번호가 붙어 있으며, 1번 카드가 제일 위에, N번 카드가 제일 아래인 상태로 순서대로 카드가 놓여 있다. 이제 다음과 같은 동작을 카드가 www.acmicpc.net 풀이 class Queue { constructor() { this.data = []; this.head = 0; this.tail = 0; } push(item) { this.data[this.tail++] = item; } pop() { this.head++; } front() { return this.data[this.head]; } rear() { return this.data[thi..