diff --git "a/nkim/week5/K\353\262\210\354\247\270\354\210\230.js" "b/nkim/week5/K\353\262\210\354\247\270\354\210\230.js" new file mode 100644 index 0000000..78a6920 --- /dev/null +++ "b/nkim/week5/K\353\262\210\354\247\270\354\210\230.js" @@ -0,0 +1,10 @@ +function solution(array, commands) { + var answer = []; + + commands.forEach(([i, j, k]) => { + const slice_arr = array.slice(i - 1, j); + slice_arr.sort((a, b) => a - b); + answer.push(slice_arr[k - 1]); + }); + return answer; +} diff --git "a/nkim/week5/\353\252\250\354\235\230\352\263\240\354\202\254.js" "b/nkim/week5/\353\252\250\354\235\230\352\263\240\354\202\254.js" new file mode 100644 index 0000000..3ea216a --- /dev/null +++ "b/nkim/week5/\353\252\250\354\235\230\352\263\240\354\202\254.js" @@ -0,0 +1,25 @@ +function solution(answers) { + var answer = []; + + const answer_cnt = [0, 0, 0]; + const pattern1 = [1, 2, 3, 4, 5]; //5 + const pattern2 = [2, 1, 2, 3, 2, 4, 2, 5]; //8 + const pattern3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]; //10 + + answers.forEach((answer, idx) => { + if (pattern1[idx % pattern1.length] === answer) answer_cnt[0] += 1; + if (pattern2[idx % pattern2.length] === answer) answer_cnt[1] += 1; + if (pattern3[idx % pattern3.length] === answer) answer_cnt[2] += 1; + }); + + const max = Math.max(...answer_cnt); + let idx = answer_cnt.indexOf(max); + let i; + while (idx != -1) { + answer.push(idx + 1); + i = idx + 1; + idx = answer_cnt.indexOf(max, i); + } + + return answer; +} diff --git "a/nkim/week5/\354\213\240\352\263\240 \352\262\260\352\263\274 \353\260\233\352\270\260.js" "b/nkim/week5/\354\213\240\352\263\240 \352\262\260\352\263\274 \353\260\233\352\270\260.js" new file mode 100644 index 0000000..540b2a6 --- /dev/null +++ "b/nkim/week5/\354\213\240\352\263\240 \352\262\260\352\263\274 \353\260\233\352\270\260.js" @@ -0,0 +1,28 @@ +function solution(id_list, report, k) { + var answer = {}; + const repoCount = {}; + const repoSet = {}; + const repoFilter = new Set(); + const stopId = new Set(); + + id_list.forEach((id) => { + answer[id] = 0; + repoCount[id] = 0; + repoSet[id] = []; + }); + report.forEach((data) => repoFilter.add(data)); + repoFilter.forEach((repo) => { + const [user_id, report_id] = repo.split(" "); + repoCount[report_id] += 1; + if (repoCount[report_id] >= k) stopId.add(report_id); + repoSet[user_id].push(report_id); + }); + Object.entries(repoSet).forEach(([user_id, report_id_list]) => { + stopId.forEach((stop_id) => { + if (report_id_list.includes(stop_id)) answer[user_id] += 1; + }); + }); + answer = Object.values(answer); + + return answer; +}