Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Programmers/Level2/131127_할인_행사.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,53 @@
링크 : https://school.programmers.co.kr/learn/courses/30/lessons/131127
*/

// ANCHOR - 2025.12.07 풀이
function solution(want, number, discount) {
// 원하는 제품 정보 Map 초기화
const wantMap = new Map();
for (let idx = 0; idx < want.length; idx++) {
wantMap.set(want[idx], number[idx]);
}

// 슬라이딩 윈도우에 필요한 변수들 정의
let answer = 0;

// 첫번째 윈도우 처리
for (let day = 0; day <= 9; day++) {
const product = discount[day];
if (wantMap.has(product)) {
wantMap.set(product, wantMap.get(product) - 1);
}
}

if ([...wantMap.values()].every((num) => num <= 0)) {
answer += 1;
}

// 슬라이딩 윈도우
for (let idx = 0; idx < discount.length - 10; idx++) {
// 앞의 것 빼기
const first = discount[idx];
if (wantMap.has(first)) {
wantMap.set(first, wantMap.get(first) + 1);
}

// 뒤의 것 추가하기
const last = discount[idx + 10];
if (wantMap.has(last)) {
wantMap.set(last, wantMap.get(last) - 1);
}

// 가입 가능 여부 확인
if ([...wantMap.values()].every((num) => num <= 0)) {
answer++;
}
}

return answer;
}

// ANCHOR - 2025.10.06 풀이
function isAnswer(wantMap) {
// wantMap의 모든 제품 수량이 0보다 작은지 (답이 되는지) 확인하기
return [...wantMap.values()].every((value) => value <= 0);
Expand Down
21 changes: 21 additions & 0 deletions Programmers/Level2/42888_오픈채팅방.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@
링크 : https://school.programmers.co.kr/learn/courses/30/lessons/42888
*/

// ANCHOR - 2025.12.07 풀이
function solution(record) {
const userMap = new Map();
for (let idx = 0; idx < record.length; idx++) {
const [type, uid, name] = record[idx].split(" ");
if (type === "Enter" || type === "Change") {
userMap.set(uid, name);
}
}

const answer = [];
for (let idx = 0; idx < record.length; idx++) {
const [type, uid, _] = record[idx].split(" ");
if (type === "Enter") answer.push(`${userMap.get(uid)}님이 들어왔습니다.`);
else if (type === "Leave")
answer.push(`${userMap.get(uid)}님이 나갔습니다.`);
}

return answer;
}

// ANCHOR 2025.10.06 풀이
function solution2(record) {
const nicknameMap = new Map(); // key: 유저 아이디, value: 현재 닉네임
Expand Down