Logo
Hyunsu Blog
this

๐Ÿ“†Published :Mar 25, 2024 โ€ข

๐Ÿ“†Updated :Mar 25, 2024 โ€ข

โ˜•๏ธ2min

2022 KAKAO TECH INTERNSHIP ์„ฑ๊ฒฉ ์œ ํ˜• ๊ฒ€์‚ฌ

99์ฝ”ํ…Œ ์Šคํ„ฐ๋””๋ฅผ ์‹œ์ž‘ํ–ˆ๋‹ค. ๋งค์ฃผ ์›”,๋ชฉ ์ €๋… 9์‹œ์— ๋ชจ์—ฌ 11์‹œ๊นŒ์ง€ ์ฃผ์–ด์ง„ ๋ฌธ์ œ๋“ค์„ ๊ทธ ์ž๋ฆฌ์—์„œ ํ’€๊ณ , ์Šคํ„ฐ๋””์žฅ๋‹˜์ด ํ’€์ด๋ฅผ ์„ค๋ช…ํ•ด ์ค€๋‹ค. ์˜ค๋Š˜์€ 2022 ์นด์นด์˜ค ์ธํ„ด์‹ญ ์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ ๋ฌธ์ œ์ด๋‹ค.

๋ฌธ์ œ

๋ฌธ์ œ ์ถœ์ฒ˜ : ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2022 ์นด์นด์˜ค ์ธํ„ด์‹ญ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ

๋‚˜๋งŒ์˜ ์นด์นด์˜ค ์„ฑ๊ฒฉ ์œ ํ˜• ๊ฒ€์‚ฌ์ง€๋ฅผ ๋งŒ๋“ค๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์„ฑ๊ฒฉ ์œ ํ˜• ๊ฒ€์‚ฌ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ 4๊ฐœ ์ง€ํ‘œ๋กœ ์„ฑ๊ฒฉ ์œ ํ˜•์„ ๊ตฌ๋ถ„ํ•ฉ๋‹ˆ๋‹ค. ์„ฑ๊ฒฉ์€ ๊ฐ ์ง€ํ‘œ์—์„œ ๋‘ ์œ ํ˜• ์ค‘ ํ•˜๋‚˜๋กœ ๊ฒฐ์ •๋ฉ๋‹ˆ๋‹ค.

์ง€ํ‘œ ๋ฒˆํ˜ธ ์„ฑ๊ฒฉ ์œ ํ˜• 1๋ฒˆ ์ง€ํ‘œ ๋ผ์ด์–ธํ˜•(R), ํŠœ๋ธŒํ˜•(T) 2๋ฒˆ ์ง€ํ‘œ ์ฝ˜ํ˜•(C), ํ”„๋กœ๋„ํ˜•(F) 3๋ฒˆ ์ง€ํ‘œ ์ œ์ด์ง€ํ˜•(J), ๋ฌด์ง€ํ˜•(M) 4๋ฒˆ ์ง€ํ‘œ ์–ดํ”ผ์น˜ํ˜•(A), ๋„ค์˜คํ˜•(N) 4๊ฐœ์˜ ์ง€ํ‘œ๊ฐ€ ์žˆ์œผ๋ฏ€๋กœ ์„ฑ๊ฒฉ ์œ ํ˜•์€ ์ด 16(=2 x 2 x 2 x 2)๊ฐ€์ง€๊ฐ€ ๋‚˜์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, "RFMN"์ด๋‚˜ "TCMA"์™€ ๊ฐ™์€ ์„ฑ๊ฒฉ ์œ ํ˜•์ด ์žˆ์Šต๋‹ˆ๋‹ค.

๊ฒ€์‚ฌ์ง€์—๋Š” ์ด n๊ฐœ์˜ ์งˆ๋ฌธ์ด ์žˆ๊ณ , ๊ฐ ์งˆ๋ฌธ์—๋Š” ์•„๋ž˜์™€ ๊ฐ™์€ 7๊ฐœ์˜ ์„ ํƒ์ง€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

๋งค์šฐ ๋น„๋™์˜ ๋น„๋™์˜ ์•ฝ๊ฐ„ ๋น„๋™์˜ ๋ชจ๋ฅด๊ฒ ์Œ ์•ฝ๊ฐ„ ๋™์˜ ๋™์˜ ๋งค์šฐ ๋™์˜ ๊ฐ ์งˆ๋ฌธ์€ 1๊ฐ€์ง€ ์ง€ํ‘œ๋กœ ์„ฑ๊ฒฉ ์œ ํ˜• ์ ์ˆ˜๋ฅผ ํŒ๋‹จํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด, ์–ด๋–ค ํ•œ ์งˆ๋ฌธ์—์„œ 4๋ฒˆ ์ง€ํ‘œ๋กœ ์•„๋ž˜ ํ‘œ์ฒ˜๋Ÿผ ์ ์ˆ˜๋ฅผ ๋งค๊ธธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์„ ํƒ์ง€ ์„ฑ๊ฒฉ ์œ ํ˜• ์ ์ˆ˜ ๋งค์šฐ ๋น„๋™์˜ ๋„ค์˜คํ˜• 3์  ๋น„๋™์˜ ๋„ค์˜คํ˜• 2์  ์•ฝ๊ฐ„ ๋น„๋™์˜ ๋„ค์˜คํ˜• 1์  ๋ชจ๋ฅด๊ฒ ์Œ ์–ด๋–ค ์„ฑ๊ฒฉ ์œ ํ˜•๋„ ์ ์ˆ˜๋ฅผ ์–ป์ง€ ์•Š์Šต๋‹ˆ๋‹ค ์•ฝ๊ฐ„ ๋™์˜ ์–ดํ”ผ์น˜ํ˜• 1์  ๋™์˜ ์–ดํ”ผ์น˜ํ˜• 2์  ๋งค์šฐ ๋™์˜ ์–ดํ”ผ์น˜ํ˜• 3์  ์ด๋•Œ ๊ฒ€์‚ฌ์ž๊ฐ€ ์งˆ๋ฌธ์—์„œ ์•ฝ๊ฐ„ ๋™์˜ ์„ ํƒ์ง€๋ฅผ ์„ ํƒํ•  ๊ฒฝ์šฐ ์–ดํ”ผ์น˜ํ˜•(A) ์„ฑ๊ฒฉ ์œ ํ˜• 1์ ์„ ๋ฐ›๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ๊ฒ€์‚ฌ์ž๊ฐ€ ๋งค์šฐ ๋น„๋™์˜ ์„ ํƒ์ง€๋ฅผ ์„ ํƒํ•  ๊ฒฝ์šฐ ๋„ค์˜คํ˜•(N) ์„ฑ๊ฒฉ ์œ ํ˜• 3์ ์„ ๋ฐ›๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

์œ„ ์˜ˆ์‹œ์ฒ˜๋Ÿผ ๋„ค์˜คํ˜•์ด ๋น„๋™์˜, ์–ดํ”ผ์น˜ํ˜•์ด ๋™์˜์ธ ๊ฒฝ์šฐ๋งŒ ์ฃผ์–ด์ง€์ง€ ์•Š๊ณ , ์งˆ๋ฌธ์— ๋”ฐ๋ผ ๋„ค์˜คํ˜•์ด ๋™์˜, ์–ดํ”ผ์น˜ํ˜•์ด ๋น„๋™์˜์ธ ๊ฒฝ์šฐ๋„ ์ฃผ์–ด์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ๊ฐ ์„ ํƒ์ง€๋Š” ๊ณ ์ •์ ์ธ ํฌ๊ธฐ์˜ ์ ์ˆ˜๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

๋งค์šฐ ๋™์˜๋‚˜ ๋งค์šฐ ๋น„๋™์˜ ์„ ํƒ์ง€๋ฅผ ์„ ํƒํ•˜๋ฉด 3์ ์„ ์–ป์Šต๋‹ˆ๋‹ค. ๋™์˜๋‚˜ ๋น„๋™์˜ ์„ ํƒ์ง€๋ฅผ ์„ ํƒํ•˜๋ฉด 2์ ์„ ์–ป์Šต๋‹ˆ๋‹ค. ์•ฝ๊ฐ„ ๋™์˜๋‚˜ ์•ฝ๊ฐ„ ๋น„๋™์˜ ์„ ํƒ์ง€๋ฅผ ์„ ํƒํ•˜๋ฉด 1์ ์„ ์–ป์Šต๋‹ˆ๋‹ค. ๋ชจ๋ฅด๊ฒ ์Œ ์„ ํƒ์ง€๋ฅผ ์„ ํƒํ•˜๋ฉด ์ ์ˆ˜๋ฅผ ์–ป์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๊ฒ€์‚ฌ ๊ฒฐ๊ณผ๋Š” ๋ชจ๋“  ์งˆ๋ฌธ์˜ ์„ฑ๊ฒฉ ์œ ํ˜• ์ ์ˆ˜๋ฅผ ๋”ํ•˜์—ฌ ๊ฐ ์ง€ํ‘œ์—์„œ ๋” ๋†’์€ ์ ์ˆ˜๋ฅผ ๋ฐ›์€ ์„ฑ๊ฒฉ ์œ ํ˜•์ด ๊ฒ€์‚ฌ์ž์˜ ์„ฑ๊ฒฉ ์œ ํ˜•์ด๋ผ๊ณ  ํŒ๋‹จํ•ฉ๋‹ˆ๋‹ค. ๋‹จ, ํ•˜๋‚˜์˜ ์ง€ํ‘œ์—์„œ ๊ฐ ์„ฑ๊ฒฉ ์œ ํ˜• ์ ์ˆ˜๊ฐ€ ๊ฐ™์œผ๋ฉด, ๋‘ ์„ฑ๊ฒฉ ์œ ํ˜• ์ค‘ ์‚ฌ์ „ ์ˆœ์œผ๋กœ ๋น ๋ฅธ ์„ฑ๊ฒฉ ์œ ํ˜•์„ ๊ฒ€์‚ฌ์ž์˜ ์„ฑ๊ฒฉ ์œ ํ˜•์ด๋ผ๊ณ  ํŒ๋‹จํ•ฉ๋‹ˆ๋‹ค.

์งˆ๋ฌธ๋งˆ๋‹ค ํŒ๋‹จํ•˜๋Š” ์ง€ํ‘œ๋ฅผ ๋‹ด์€ 1์ฐจ์› ๋ฌธ์ž์—ด ๋ฐฐ์—ด survey์™€ ๊ฒ€์‚ฌ์ž๊ฐ€ ๊ฐ ์งˆ๋ฌธ๋งˆ๋‹ค ์„ ํƒํ•œ ์„ ํƒ์ง€๋ฅผ ๋‹ด์€ 1์ฐจ์› ์ •์ˆ˜ ๋ฐฐ์—ด choices๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ์ด๋•Œ, ๊ฒ€์‚ฌ์ž์˜ ์„ฑ๊ฒฉ ์œ ํ˜• ๊ฒ€์‚ฌ ๊ฒฐ๊ณผ๋ฅผ ์ง€ํ‘œ ๋ฒˆํ˜ธ ์ˆœ์„œ๋Œ€๋กœ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

์ œํ•œ์‚ฌํ•ญ 1 โ‰ค survey์˜ ๊ธธ์ด ( = n) โ‰ค 1,000 survey์˜ ์›์†Œ๋Š” "RT", "TR", "FC", "CF", "MJ", "JM", "AN", "NA" ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค. survey[i]์˜ ์ฒซ ๋ฒˆ์งธ ์บ๋ฆญํ„ฐ๋Š” i+1๋ฒˆ ์งˆ๋ฌธ์˜ ๋น„๋™์˜ ๊ด€๋ จ ์„ ํƒ์ง€๋ฅผ ์„ ํƒํ•˜๋ฉด ๋ฐ›๋Š” ์„ฑ๊ฒฉ ์œ ํ˜•์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. survey[i]์˜ ๋‘ ๋ฒˆ์งธ ์บ๋ฆญํ„ฐ๋Š” i+1๋ฒˆ ์งˆ๋ฌธ์˜ ๋™์˜ ๊ด€๋ จ ์„ ํƒ์ง€๋ฅผ ์„ ํƒํ•˜๋ฉด ๋ฐ›๋Š” ์„ฑ๊ฒฉ ์œ ํ˜•์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. choices์˜ ๊ธธ์ด = survey์˜ ๊ธธ์ด

choices[i]๋Š” ๊ฒ€์‚ฌ์ž๊ฐ€ ์„ ํƒํ•œ i+1๋ฒˆ์งธ ์งˆ๋ฌธ์˜ ์„ ํƒ์ง€๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. 1 โ‰ค choices์˜ ์›์†Œ โ‰ค 7 choices ๋œป

1 ๋งค์šฐ ๋น„๋™์˜ 2 ๋น„๋™์˜ 3 ์•ฝ๊ฐ„ ๋น„๋™์˜ 4 ๋ชจ๋ฅด๊ฒ ์Œ 5 ์•ฝ๊ฐ„ ๋™์˜ 6 ๋™์˜ 7 ๋งค์šฐ ๋™์˜

์ž…์ถœ๋ ฅ ์˜ˆ

survey choices result ["AN", "CF", "MJ", "RT", "NA"] [5, 3, 2, 7, 5] "TCMA" ["TR", "RT", "TR"] [7, 1, 3] "RCJA"`

๋ฌธ์ œ ์ ‘๊ทผ๋ฒ•

1. ์ตœ์ดˆ ์ ‘๊ทผ ๋ฐฉ๋ฒ•

์ฃผ์–ด์ง„ survey์™€ choice๋Š” 1:1 ๋Œ€์‘ ๊ด€๊ณ„์ด๋‹ค . "AN" ์ด๋ผ๋Š” survey๊ฐ€ ์ฃผ์–ด์ง€๋ฉด, choice๋Š” 5๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. 5 ๋Š” choices์— ๋”ฐ๋ฅด๋ฉด ์•ฝ๊ฐ„ ๋™์˜๋ฅผ ์˜๋ฏธํ•œ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ์ด ๋™์˜๊ฐ€ ์„ฑ๊ฒฉ ์œ ํ˜• A ๋ฅผ ์˜๋ฏธํ•˜๋Š”์ง€ N์„ ์˜๋ฏธํ•˜๋Š”์ง€๋Š” ์˜๋ฏธํ•˜๋Š”์ง€๋Š” survey๊ฐ€ "AN"์ธ์ง€ "NA"์ธ์ง€์— ๋”ฐ๋ผ ๋‹ฌ๋ผ์ง„๋‹ค.

์ด ๋ถ€๋ถ„์„ ์œ ์˜ํ•ด์„œ ํ’€์–ด์•ผ ํ•œ๋‹ค.

๊ฒฐ๊ตญ ๊ฐ€์žฅ ๋งŽ์€ ์ ์ˆ˜๋ฅผ ๋ฐ›์€ ์œ ํ˜•์„ ๋ฝ‘์œผ๋ฉด ๋œ๋‹ค.๋‹จ, ๊ฐ™์€ ์ ์ˆ˜์ผ ๊ฒฝ์šฐ๋Š” ์‚ฌ์ „์ˆœ์œผ๋กœ ์•ž์— ์žˆ๋Š” ์œ ํ˜•์„ ๋ฝ‘์•„์•ผ ํ•œ๋‹ค. result_mapper ๋ผ๋Š” ๋”•์…”๋„ˆ๋ฆฌ๋ฅผ ๋งŒ๋“ค์–ด์„œ survey์˜ ๊ฐ ์š”์†Œ์— ๋”ฐ๋ผ ์ ์ˆ˜๋ฅผ ๋งค๊ฒจ์„œ {"R":[ ์„ ํƒํ•œ ์ ์ˆ˜, ๋ช‡ ๋ฒˆ ์œ ํ˜•์ธ์ง€]}ํ˜•ํƒœ๋กœ ์ €์žฅํ–ˆ๋‹ค. ๊ทธ๋ ‡๊ฒŒ ๋ชจ๋“  choice์˜ ์ ์ˆ˜๋ฅผ ๋งค๊ธด ํ›„, ๋‹ค์‹œ result_mapper๋ฅผ ๋Œ๋ฉด์„œ ๊ฐ€์žฅ ๋†’์€ ์ ์ˆ˜๋ฅผ ๊ฐ€์ง„ ์œ ํ˜•์„ ๋ฝ‘์•„ ๋‚ด์—ˆ๋‹ค.

def solution(survey, choices): answer = '' choice_range = [0, 3, 2, 1, 0, 1, 2, 3] result_mapper ={ "R":[ 0, 1], "T":[0,1], "C":[0,2], "F":[0,2], "J":[0,3], "M":[0,3], "A":[0,4], "N":[0,4] } for i in range(len(survey)): personality_type="" if(choices[i] !=4 and choices[i] >4): #๋™์˜ personality_type=survey[i][1] result_mapper[personality_type][0] = result_mapper[personality_type][0]+choice_range[choices[i]] if(choices[i] !=4 and choices[i]<4): #๋น„๋™์˜ personality_type=survey[i][0] result_mapper[personality_type][0] = result_mapper[personality_type][0]+choice_range[choices[i]] #๋†’์€ ์ ์ˆ˜ ๋ณ„๋กœ ๋ฌถ๊ธฐ keys = list(result_mapper.keys()) for i in range(0,4): #ํฐ ๊ฐ€ if(result_mapper[keys[i*2]][0] == result_mapper[keys[i*2+1]][0]): sortedType=sorted([keys[i*2], keys[i*2+1]]) answer+=sortedType[0] continue if(result_mapper[keys[i*2]][0] > result_mapper[keys[i*2+1]][0]): #i๋ฒˆ์งธ๊ฐ€ ํฌ๋‹ค answer+=keys[i*2] else: answer+=keys[i*2+1] return answer

2. ํŒŒ์ด์ฌ์˜ ์ž๋ฃŒ๊ตฌ๋ฃŒ๋ฅผ ์ข€ ๋” ํ™œ์šฉํ•œ ์ ‘๊ทผ๋ฒ•

์ด 16๊ฐœ์˜ ํƒ€์ž…์— ๋Œ€ํ•œ ์ ์ˆ˜๋ฅผ ์ €์žฅํ•˜๋Š” ๋”•์…”๋„ˆ๋ฆฌ๋ฅผ ๋งŒ๋“œ๋Š”๊ฑด ์‰ฌ์šด๋ฐ, ๊ทธ ํ›„ ์œ ํ˜• ๋ณ„๋กœ 2๊ฐœํƒ€์ž…์”ฉ ๋ฌถ์–ด์„œ ๋น„๊ตํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ๋‚ด๊ฐ€ ์ตœ์ดˆ ์ ‘๊ทผํ•œ ๋ฐฉ๋ฒ•์—์„œ๋Š” ์˜คํžˆ๋ ค ๋กœ์ง์„ ๋” ๋ณต์žกํ•˜๊ฒŒ ๋งŒ๋“ ๋‹ค

zip ์„ ์ด์šฉํ•˜์—ฌ 4๊ฐ€์ง€ ์”ฉ ๋ฌถ์–ด ๋‘ ๊ทธ๋ฃน์œผ๋กœ ๋‚˜๋ˆ„์–ด ๋น„๊ตํ•˜๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ์ ‘๊ทผํ•˜๋ฉด ๋” ๊ฐ„๋‹จํ•˜๊ฒŒ ํ’€ ์ˆ˜ ์žˆ๋‹ค.

images/kakao-2022-internship-personality-type-1

RFJA์™€ TFMN ์œผ๋กœ ๋‚˜๋ˆ„์–ด zip์„ ์ด์šฉํ•˜์—ฌ ๋ฌถ์–ด ์ค€ํ›„ ์ˆœํšŒํ•˜๋ฉด, ์ˆœํšŒํ•  ๋•Œ R์˜ ์ ์ˆ˜์™€ T์˜ ์ ์ˆ˜๋ฅผ ๋น„๊ตํ•˜์—ฌ ๋†’์€ ์ ์ˆ˜๋ฅผ ๊ฐ€์ง„ ์œ ํ˜•์„ ์„ ํƒํ•˜๋ฉด ๋œ๋‹ค.

from collections import defaultdict def solution(survey, choices): answer = '' result_mapper = defaultdict(int) for i in range(len(survey)): if(choices[i] !=4 and choices[i] >4): #๋™์˜ result_mapper[survey[i][1]]+=choices[i] - 4 if(choices[i] !=4 and choices[i]<4): #๋น„๋™์˜ result_mapper[survey[i][0]]+= 4-choices[i] #๋†’์€ ์ ์ˆ˜ ๋ณ„๋กœ ๋ฌถ๊ธฐ RCJA, TFMN = ["R","C","J","A"],["T","F","M","N"] for type_a, type_b in zip(RCJA, TFMN): if result_mapper[type_a]>=result_mapper[type_b]: answer+=type_a else: answer+=type_b return answer

Hi, I'm Hyunsu ๐Ÿ‘‹

Profile Image

์•ˆ๋…•ํ•˜์„ธ์š”. ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ์ž ์ฃผํ˜„์ˆ˜์ž…๋‹ˆ๋‹ค.

๊ฐœ๋ฐœ์„ ํ†ตํ•ด ์‚ฌ์šฉ์ž๋“ค์—๊ฒŒ ํ’๋ถ€ํ•˜๊ณ  ๊ฐ€์น˜ ์žˆ๋Š” ๊ฒฝํ—˜์„ ์ œ๊ณตํ•˜๋Š” ์ผ์— ๋ฟŒ๋“ฏํ•จ์„ ๋Š๋‚๋‹ˆ๋‹ค.

์˜ต์‹œ๋””์–ธ(Obsidian)์—์„œ ํ˜„์žฌ ๋ธ”๋กœ๊ทธ๋กœ ํ•˜๋‚˜์”ฉ ๊ธ€์„ ์˜ฎ๊ธฐ๋Š” ๊ณผ์ •์— ์žˆ์–ด์š”. โ˜•๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป โ›ท

Github on ViewReach Me Out