๋ฐ˜์‘ํ˜•

Problem Solution/Programmers 46

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ํ”ผ์ž ๋‚˜๋ˆ  ๋จน๊ธฐ (3)

Problem Description ๋จธ์“ฑ์ด๋„ค ํ”ผ์ž๊ฐ€๊ฒŒ๋Š” ํ”ผ์ž๋ฅผ ๋‘ ์กฐ๊ฐ์—์„œ ์—ด ์กฐ๊ฐ๊นŒ์ง€ ์›ํ•˜๋Š” ์กฐ๊ฐ ์ˆ˜๋กœ ์ž˜๋ผ์ค๋‹ˆ๋‹ค. ํ”ผ์ž ์กฐ๊ฐ ์ˆ˜ slice์™€ ํ”ผ์ž๋ฅผ ๋จน๋Š” ์‚ฌ๋žŒ์˜ ์ˆ˜ n์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, n๋ช…์˜ ์‚ฌ๋žŒ์ด ์ตœ์†Œ ํ•œ ์กฐ๊ฐ ์ด์ƒ ํ”ผ์ž๋ฅผ ๋จน์œผ๋ ค๋ฉด ์ตœ์†Œ ๋ช‡ ํŒ์˜ ํ”ผ์ž๋ฅผ ์‹œ์ผœ์•ผ ํ•˜๋Š”์ง€๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions. 2 ≤ slice ≤ 10 1 ≤ n ≤ 100 Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 10๋ช…์ด 7์กฐ๊ฐ์œผ๋กœ ์ž๋ฅธ ํ”ผ์ž๋ฅผ ํ•œ ์กฐ๊ฐ ์ด์ƒ์”ฉ ๋จน์œผ๋ ค๋ฉด ์ตœ์†Œ 2ํŒ์„ ์‹œ์ผœ์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 12๋ช…์ด 4์กฐ๊ฐ์œผ๋กœ ์ž๋ฅธ ํ”ผ์ž๋ฅผ ํ•œ ์กฐ๊ฐ ์ด์ƒ์”ฉ ๋จน์œผ๋ ค๋ฉด ์ตœ์†Œ 3ํŒ์„ ์‹œ์ผœ์•ผ ํ•ฉ๋‹ˆ๋‹ค. My solution function solution(s..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ์ ์˜ ์œ„์น˜ ๊ตฌํ•˜๊ธฐ

Problem Description ์ค‘์•™๊ฐ’์€ ์–ด๋–ค ์ฃผ์–ด์ง„ ๊ฐ’๋“ค์„ ํฌ๊ธฐ์˜ ์ˆœ์„œ๋Œ€๋กœ ์ •๋ ฌํ–ˆ์„ ๋•Œ ๊ฐ€์žฅ ์ค‘์•™์— ์œ„์น˜ํ•˜๋Š” ๊ฐ’์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด 1, 2, 7, 10, 11์˜ ์ค‘์•™๊ฐ’์€ 7์ž…๋‹ˆ๋‹ค. ์ •์ˆ˜ ๋ฐฐ์—ด array๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, ์ค‘์•™๊ฐ’์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions. array์˜ ๊ธธ์ด๋Š” ํ™€์ˆ˜์ž…๋‹ˆ๋‹ค. 0 0) { return 1 } else if (dot[0] < 0 && dot[1] < 0) { return 3 } else { return 4 } } Another solutions function solution(dot) { const [num,num2] = dot; con..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ์ค‘์•™๊ฐ’ ๊ตฌํ•˜๊ธฐ

Problem Description ์ค‘์•™๊ฐ’์€ ์–ด๋–ค ์ฃผ์–ด์ง„ ๊ฐ’๋“ค์„ ํฌ๊ธฐ์˜ ์ˆœ์„œ๋Œ€๋กœ ์ •๋ ฌํ–ˆ์„ ๋•Œ ๊ฐ€์žฅ ์ค‘์•™์— ์œ„์น˜ํ•˜๋Š” ๊ฐ’์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด 1, 2, 7, 10, 11์˜ ์ค‘์•™๊ฐ’์€ 7์ž…๋‹ˆ๋‹ค. ์ •์ˆ˜ ๋ฐฐ์—ด array๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, ์ค‘์•™๊ฐ’์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions. array์˜ ๊ธธ์ด๋Š” ํ™€์ˆ˜์ž…๋‹ˆ๋‹ค. 0 < array์˜ ๊ธธ์ด < 100 -1,000

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ์™ธ๊ณ„ํ–‰์„ฑ์˜ ๋‚˜์ด

Problem Description. ์šฐ์ฃผ์—ฌํ–‰์„ ํ•˜๋˜ ๋จธ์“ฑ์ด๋Š” ์—”์ง„ ๊ณ ์žฅ์œผ๋กœ PROGRAMMERS-962 ํ–‰์„ฑ์— ๋ถˆ์‹œ์ฐฉํ•˜๊ฒŒ ๋์Šต๋‹ˆ๋‹ค. ์ž…๊ตญ์‹ฌ์‚ฌ์—์„œ ๋‚˜์ด๋ฅผ ๋งํ•ด์•ผ ํ•˜๋Š”๋ฐ, PROGRAMMERS-962 ํ–‰์„ฑ์—์„œ๋Š” ๋‚˜์ด๋ฅผ ์•ŒํŒŒ๋ฒณ์œผ๋กœ ๋งํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. a๋Š” 0, b๋Š” 1, c๋Š” 2, ..., j๋Š” 9์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด 23์‚ด์€ cd, 51์‚ด์€ fb๋กœ ํ‘œํ˜„ํ•ฉ๋‹ˆ๋‹ค. ๋‚˜์ด age๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ PROGRAMMER-962์‹ ๋‚˜์ด๋ฅผ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. Restrictions. age๋Š” ์ž์—ฐ์ˆ˜์ž…๋‹ˆ๋‹ค. age ≤ 1,000 PROGRAMMERS-962 ํ–‰์„ฑ์€ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋งŒ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. Input/Output Example. age result 23 "cd" 51 "fb" 100..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ๋ฌธ์ž์—ด ์ •๋ ฌํ•˜๊ธฐ (1)

Problem Description ๋ฌธ์ž์—ด my_string์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, my_string ์•ˆ์— ์žˆ๋Š” ์ˆซ์ž๋งŒ ๊ณจ๋ผ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•œ ๋ฆฌ์ŠคํŠธ๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด๋ณด์„ธ์š”. Restrictions. 1 ≤ my_string์˜ ๊ธธ์ด ≤ 100 my_string์—๋Š” ์ˆซ์ž๊ฐ€ ํ•œ ๊ฐœ ์ด์ƒ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. my_string์€ ์˜์–ด ์†Œ๋ฌธ์ž ๋˜๋Š” 0๋ถ€ํ„ฐ 9๊นŒ์ง€์˜ ์ˆซ์ž๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. - - - Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 "hi12392"์— ์žˆ๋Š” ์ˆซ์ž 1, 2, 3, 9, 2๋ฅผ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•œ [1, 2, 2, 3, 9]๋ฅผ return ํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 "p2o4i8gj2"์— ์žˆ๋Š” ์ˆซ์ž 2, 4, 8, 2๋ฅผ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•œ [2, 2, 4,..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ๊ฐ€์žฅ ํฐ ์ˆ˜ ์ฐพ๊ธฐ

Problem Description ์ •์ˆ˜ ๋ฐฐ์—ด array๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, ๊ฐ€์žฅ ํฐ ์ˆ˜์™€ ๊ทธ ์ˆ˜์˜ ์ธ๋ฑ์Šค๋ฅผ ๋‹ด์€ ๋ฐฐ์—ด์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions. 1 ≤ array์˜ ๊ธธ์ด ≤ 100 0 ≤ array ์›์†Œ ≤ 1,000 array์— ์ค‘๋ณต๋œ ์ˆซ์ž๋Š” ์—†์Šต๋‹ˆ๋‹ค. Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 1, 8, 3 ์ค‘ ๊ฐ€์žฅ ํฐ ์ˆ˜๋Š” 8์ด๊ณ  ์ธ๋ฑ์Šค 1์— ์žˆ์Šต๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 9, 10, 11, 8 ์ค‘ ๊ฐ€์žฅ ํฐ ์ˆ˜๋Š” 11์ด๊ณ  ์ธ๋ฑ์Šค 2์— ์žˆ์Šต๋‹ˆ๋‹ค. My solution function solution(array) { var answer = []; answer.push(Math.max(...array)) answer.push(arra..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ์ตœ๋Œ“๊ฐ’ ๋งŒ๋“ค๊ธฐ (2)

Problem Description ์ •์ˆ˜ ๋ฐฐ์—ด numbers๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. numbers์˜ ์›์†Œ ์ค‘ ๋‘ ๊ฐœ๋ฅผ ๊ณฑํ•ด ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ์ตœ๋Œ“๊ฐ’์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. Restrictions. -10,000 ≤ numbers์˜ ์›์†Œ ≤ 10,000 2 ≤ numbers ์˜ ๊ธธ์ด ≤ 100. Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 ๋‘ ์ˆ˜์˜ ๊ณฑ์ค‘ ์ตœ๋Œ“๊ฐ’์€ -3 * -5 = 15 ์ž…๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 ๋‘ ์ˆ˜์˜ ๊ณฑ์ค‘ ์ตœ๋Œ“๊ฐ’์€ 10 * 24 = 240 ์ž…๋‹ˆ๋‹ค. My solution function solution(numbers) { numbers.sort((a, b) => a - b); const length = numbers.length; const posi..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ๊ฐ€์œ„ ๋ฐ”์œ„ ๋ณด

Problem Description ๊ฐ€์œ„๋Š” 2 ๋ฐ”์œ„๋Š” 0 ๋ณด๋Š” 5๋กœ ํ‘œํ˜„ํ•ฉ๋‹ˆ๋‹ค. ๊ฐ€์œ„ ๋ฐ”์œ„ ๋ณด๋ฅผ ๋‚ด๋Š” ์ˆœ์„œ๋Œ€๋กœ ๋‚˜ํƒ€๋‚ธ ๋ฌธ์ž์—ด rsp๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, rsp์— ์ €์žฅ๋œ ๊ฐ€์œ„ ๋ฐ”์œ„ ๋ณด๋ฅผ ๋ชจ๋‘ ์ด๊ธฐ๋Š” ๊ฒฝ์šฐ๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ๋‚˜ํƒ€๋‚ธ ๋ฌธ์ž์—ด์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions. 0 < rsp์˜ ๊ธธ์ด ≤ 100 rsp์™€ ๊ธธ์ด๊ฐ€ ๊ฐ™์€ ๋ฌธ์ž์—ด์„ return ํ•ฉ๋‹ˆ๋‹ค. rsp๋Š” ์ˆซ์ž 0, 2, 5๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 "2"๋Š” ๊ฐ€์œ„์ด๋ฏ€๋กœ ๋ฐ”์œ„๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” "0"์„ return ํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 "205"๋Š” ์ˆœ์„œ๋Œ€๋กœ ๊ฐ€์œ„, ๋ฐ”์œ„, ๋ณด์ด๊ณ  ์ด๋ฅผ ๋ชจ๋‘ ์ด๊ธฐ๋ ค๋ฉด ๋ฐ”์œ„, ๋ณด, ๊ฐ€์œ„๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ๋‚ด์•ผํ•˜๋ฏ€๋กœ “052”๋ฅผ returnํ•ฉ..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] n์˜ ๋ฐฐ์ˆ˜ ๊ณ ๋ฅด๊ธฐ

Problem Description ๋ฌธ์ž์—ด my_string์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. my_string์•ˆ์˜ ๋ชจ๋“  ์ž์—ฐ์ˆ˜๋“ค์˜ ํ•ฉ์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.์ •์ˆ˜ n๊ณผ ์ •์ˆ˜ ๋ฐฐ์—ด numlist๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, numlist์—์„œ n์˜ ๋ฐฐ์ˆ˜๊ฐ€ ์•„๋‹Œ ์ˆ˜๋“ค์„ ์ œ๊ฑฐํ•œ ๋ฐฐ์—ด์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. Restrictions. 1 ≤ n ≤ 10,000 1 ≤ numlist์˜ ํฌ๊ธฐ ≤ 100 1 ≤ numlist์˜ ์›์†Œ ≤ 100,000 Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 numlist์—์„œ 3์˜ ๋ฐฐ์ˆ˜๋งŒ์„ ๋‚จ๊ธด [6, 9, 12]๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 numlist์—์„œ 5์˜ ๋ฐฐ์ˆ˜๋งŒ์„ ๋‚จ๊ธด [10, 5]๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ๋Œ€๋ฌธ์ž์™€ ์†Œ๋ฌธ์ž

Problem Description ๋ฌธ์ž์—ด my_string์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, ๋Œ€๋ฌธ์ž๋Š” ์†Œ๋ฌธ์ž๋กœ ์†Œ๋ฌธ์ž๋Š” ๋Œ€๋ฌธ์ž๋กœ ๋ณ€ํ™˜ํ•œ ๋ฌธ์ž์—ด์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. Restrictions 1 ≤ my_string์˜ ๊ธธ์ด ≤ 1,000 my_string์€ ์˜์–ด ๋Œ€๋ฌธ์ž์™€ ์†Œ๋ฌธ์ž๋กœ๋งŒ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ # 1 ์†Œ๋ฌธ์ž๋Š” ๋Œ€๋ฌธ์ž๋กœ ๋Œ€๋ฌธ์ž๋Š” ์†Œ๋ฌธ์ž๋กœ ๋ฐ”๊พผ "CCCccc"๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 ์†Œ๋ฌธ์ž๋Š” ๋Œ€๋ฌธ์ž๋กœ ๋Œ€๋ฌธ์ž๋Š” ์†Œ๋ฌธ์ž๋กœ ๋ฐ”๊พผ "ABcDeFGHij"๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค. My solution function solution(my_string) { return my_string.split("").map((x) => x ..

๋ฐ˜์‘ํ˜•