728x90

coding test 15

[Programmers] k์˜ ๊ฐœ์ˆ˜

๋ฌธ์ œ ์„ค๋ช… ๋ฌธ์ œ ํ’€์ด ๊ณผ์ • ์ฒ˜์Œ์—๋Š” string ํ˜•ํƒœ๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ ํฌํ•จ๋˜์–ด ์žˆ์œผ๋ฉด answer +1๋กœ ํ•˜์˜€์ง€๋งŒ, 11์˜ ๊ฒฝ์šฐ 1์„ 2๋ฒˆ count ํ•ด์•ผ ํ•˜์—ฌ ์‹คํŒจ Counter๋กœ ๊ฐฏ์ˆ˜๋ฅผ ์„ผ ํ›„ value ๊ฐ’ ๋ฐ˜ํ™˜ํ•˜์—ฌ ๊ฐœ์ˆ˜๋ฅผ answer์— ๋”ํ•ด์คŒ. from collections import Counter def solution(i, j, k): answer = 0 for num in range(i, j+1): cnt = Counter(list(str(num))) if str(k) in list(map(str, cnt.keys())): answer += cnt[f'{k}'] return answer ๋‹ค๋ฅธ ์‚ฌ๋žŒ์˜ ํ’€์ด count ํ•จ์ˆ˜ ์“ฐ๊ธฐ... def solution(i, j, k): answer = sum([..

Coding test 2023.01.05

[Programmers] ๋‘ ์ •์ˆ˜ ์‚ฌ์ด์˜ ํ•ฉ

๋ฌธ์ œ ์„ค๋ช… ๋ฌธ์ œ ํ’€์ด ๊ณผ์ • ๋ฒ”์œ„๋ฅผ ์ง€์ •ํ•ด์ฃผ๊ธฐ ์œ„ํ•ด a๊ฐ€ b๋ณด๋‹ค ํฐ ๊ฒฝ์šฐ ๋‘ ๊ฐ’์„ ๊ตํ™˜, ๊ฐ’์ด ๊ฐ™์„ ๊ฒฝ์šฐ ๋ฐ”๋กœ ๋ฆฌํ„ดํ•ด์คŒ. ๊ทธ ํ›„ ๋ฒ”์œ„ ๊ฐ’์„ ๋”ํ•ด์คŒ. def solution(a, b): answer = 0 if a b: a, b = b, a for i in range(a, b+1): answer += i return answer ๋‹ค๋ฅธ ์‚ฌ๋žŒ์˜ ํ’€์ด a๊ฐ€ b๋ณด๋‹ค ํฐ ๊ฒฝ์šฐ ๋‘ ๊ฐ’ ๊ตํ™˜ for๋ฌธ์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ๋ฒ”์œ„์˜ sum์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ„๋‹จํ•˜๊ฒŒ ํ•ด๊ฒฐ def adder(a, b): # ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•˜์„ธ์š” if a > b: a, b = b, a return sum(range(a,b+1)) - coding test url: https://school..

Coding test 2023.01.04

[Programmers] ํฌ๊ธฐ๊ฐ€ ์ž‘์€ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด

๋ฌธ์ œ ์„ค๋ช… ๋ฌธ์ œ ํ’€์ด ๊ณผ์ • t์˜ ์ž๋ฆฟ์ˆ˜๋งŒํผ ๋ฐ˜๋ณต. ๋‹จ, ๋‚จ์€ ๋ฌธ์ž์—ด์ด p์˜ ๋ฌธ์ž์—ด ๊ธธ์ด๋ณด๋‹ค ์ž‘์œผ๋ฉด ์ค‘๋‹จ t์—์„œ p์˜ ์ž๋ฆฟ์ˆ˜๋งŒํผ slicing ํ›„ ๋น„๊ต, ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์œผ๋ฉด answer์— += 1 def solution(t, p): answer = 0 for i in range(0,len(t)): if (len(t) - i) < len(p): break elif int(t[i:i+len(p)]) = int(t[i:i+len(p)]): answer += 1 return answer - coding test url: https://school.programmers.co.kr/learn/courses/30/lessons/147355 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ..

Coding test 2023.01.04

[Programmers] ๋กค์ผ€์ดํฌ ์ž๋ฅด๊ธฐ

๋ฌธ์ œ ์„ค๋ช… ๋ฌธ์ œ ํ’€์ด ๊ณผ์ • ์ฒซ ๋ฒˆ์งธ ํ’€์ด for๋ฌธ์œผ๋กœ ๋Œ์•„๊ฐ€๋ฉด์„œ ๊ฐ๊ฐ์˜ ํ† ํ•‘ ์ข…๋ฅ˜ ๊ฐœ์ˆ˜๊ฐ€ ๊ฐ™์œผ๋ฉด answer์— +1 ์‹œ๊ฐ„ ์ดˆ๊ณผ๋กœ ์‹คํŒจ def solution(topping): answer = 0 for i in range(1, len(topping)+1): if len(set(topping[:i])) == len(set(topping[i:])): answer += 1 return answer ๋‘ ๋ฒˆ์งธ ํ’€์ด(๋‹ค๋ฅธ ์‚ฌ๋žŒ ํ’€์ด ์ฐธ๊ณ ) collections์˜ Counter ํ•จ์ˆ˜ ์‚ฌ์šฉ topping์˜ ๊ฐฏ์ˆ˜๋ฅผ๊ฐœ์ˆ˜๋ฅผ ์„ผ ํ›„, ํ•˜๋‚˜์”ฉ cnt dictionary์— ๋„ฃ์–ด๊ฐ€๋ฉด์„œ ๊ฐœ์ˆ˜๋ฅผ ๋น„๊ตํ•จ. ๋‹จ์ˆœ ์Šฌ๋ผ์ด์‹ฑ์ด ์•„๋‹Œ ๋”•์…”๋„ˆ๋ฆฌ ๋ณ€๊ฒฝ์œผ๋กœ ๋ณต์žก๋„ ๊ฐ์†Œ from collections import Counter def solution..

Coding test 2022.12.23

[Programmers] ํ• ์ธ ํ–‰์‚ฌ

๋ฌธ์ œ ์„ค๋ช… ๋ฌธ์ œ ํ’€์ด ๊ณผ์ • want์™€ number๋ฅผ key, value ํ˜•ํƒœ์˜ dictionary๋กœ ๋ณ€๊ฒฝ discount๋ฅผ 10์ผ์”ฉ slicing ํ•˜๋ฉด์„œ dic๊ณผ ๋™์ผํ•  ๋•Œ๋งˆ๋‹ค answer + 1 from collections import Counter def solution(want, number, discount): answer = 0 dic = {item : val for item, val in zip(want, number)} for i in range(len(discount)-9): if dic == Counter(discount[i:i+10]): answer += 1 return answer - coding test url: https://school.programmers.co.kr/learn..

Coding test 2022.12.20

[2021 Dev-Matching] ๋กœ๋˜์˜ ์ตœ๊ณ  ์ˆœ์œ„์™€ ์ตœ์ € ์ˆœ์œ„

๋ฌธ์ œ ์„ค๋ช… ๋ฌธ์ œ ํ’€์ด ๊ณผ์ • lottos์— ์žˆ๋Š” ๋ฒˆํ˜ธ ์ค‘ win_nums์— ์žˆ๋Š” ๋ฒˆํ˜ธ๊ฐ€ ์ผ์น˜ํ•  ๊ฒฝ์šฐ count += 1 ๊ฐ€๋ ค์ ธ์žˆ๋Š” ์ˆซ์ž 0์ด ์ „๋ถ€ ๋งž์„ ๊ฒฝ์šฐ(count(0))๋Š” ์ตœ๊ณ  ์ˆœ์œ„, ๊ฐ€๋ ค์ ธ ์žˆ์ง€ ์•Š๋Š” ์ˆซ์ž๋งŒ ์ผ์น˜ํ•  ๊ฒฝ์šฐ๊ฐ€ ์ตœ์ € ์ˆœ์œ„ ๋งž๋Š” ๊ฐœ์ˆ˜๊ฐ€ 0, 1๊ฐœ์ผ ๊ฒฝ์šฐ 6์œ„์ด๋ฉฐ, ๋งž๋Š” ๊ฐœ์ˆ˜์— ๋”ฐ๋ผ ์ˆœ์œ„๋ฅผ rank์— ๋„ฃ์–ด์คŒ ๋งž๋Š” ๊ฐœ์ˆ˜์— ๋”ฐ๋ผ ๊ฐ’ ๋ฐ˜ํ™˜ def solution(lottos, win_nums): rank = [6, 6, 5, 4, 3, 2, 1] count = 0 cnt_0 = lottos.count(0) for i in win_nums: if i in lottos: count += 1 return rank[count+ cnt_0], rank[count] - coding test url: http..

Coding test 2022.12.19

[KAKAO BLIND RECRUITMENT] ์‹ ๊ณ  ๊ฒฐ๊ณผ ๋ฐ›๊ธฐ(python)

๋ฌธ์ œ ์„ค๋ช… ๋ฌธ์ œ ํ’€์ด ๊ณผ์ • ์ฒ˜์Œ ๋ฌธ์ œ๋ฅผ ๋ณด์ž๋งˆ์ž ๋“  ์ƒ๊ฐ์€ report๋ฅผ set ์ฒ˜๋ฆฌํ•˜์ž! ์˜€๋‹ค.. ์•„๋ฌด๋ž˜๋„ ์ค‘๋ณต์„ ๋จผ์ € ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€์žฅ ๊ด€๊ฑด์ด๋ผ๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค. ๊ทธ ๋‹ค์Œ์€ ๊ฐ ์‹ ๊ณ ๋ฅผ ์‹ ๊ณ ์ž ๋ณ„๋กœ dictionaryํ˜•ํƒœ๋กœ ๋งŒ๋“œ๋Š” ๊ฒƒ. ์ค‘๋ณต์ด ์—†์œผ๋‹ˆ key๋ฅผ ์‹ ๊ณ ์ž, value ๊ฐ’์„ ์‹ ๊ณ ๋‹นํ•œ ์‚ฌ๋žŒ์œผ๋กœ list๋กœ ๋งŒ๋“  ํ›„ append ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๊ฒฐ์ •ํ•จ. ์ด์ œ ์‹ ๊ณ  ๋‹นํ•œ ํšŸ์ˆ˜๋ฅผ countํ•ด์•ผ ํ•˜๋Š”๋ฐ, stop์ด๋ผ๋Š” list๋ฅผ ๋งŒ๋“ค์–ด์„œ ์‹ ๊ณ ๋‹นํ•œ ์‚ฌ๋žŒ์„ ๋„ฃ์—ˆ๊ณ , ๊ทธ ์ค‘ kํšŒ ์ด์ƒ ์‹ ๊ณ ๋‹นํ•œ ์‚ฌ๋žŒ๋งŒ ๋‚จ๋„๋ก ํ–ˆ๋‹ค. ์ด์ œ dictionary์— ์žˆ๋Š” ์‹ ๊ณ ์ž์™€ ์‹ ๊ณ  ๋‹นํ•œ ์‚ฌ๋žŒ์„ ๊ฐ๊ฐ items๋กœ ํ’€์–ด์„œ ์‹ ๊ณ ๋‹นํ•œ ์‚ฌ๋žŒ์ด stop์— ์žˆ์œผ๋ฉด count์— + 1 ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ–ˆ๋‹ค. from collections import d..

Coding test 2022.12.16

[KAKAO TECH INTERNSHIP 2022] ์„ฑ๊ฒฉ ์œ ํ˜• ๊ฒ€์‚ฌํ•˜๊ธฐ(python)

๋ฌธ์ œ ์„ค๋ช… ๋ฌธ์ œ ํ’€์ด ๊ณผ์ • ํฌ์ธํŠธ๋Š” ์•ž์— ์žˆ๋Š” ๋™์ ์ผ ๊ฒฝ์šฐ ์•ž์˜ ์œ ํ˜• ๊ธ€์ž๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ def solution(survey, choices): sur = {'R': 0, 'T': 0, 'C': 0, 'F': 0, 'J': 0, 'M':0, 'A': 0, 'N':0} score = [3,2,1,0,1,2,3] answer = '' for tp, sc in zip(survey, choices): if sc 4: sur[tp[1:]] += score[sc-1] if sur['R'] >= sur['T']: answer += 'R' else: answer += 'T' if sur['C'] >= sur['F']: answer += 'C' ..

Coding test 2022.12.16

[Programmers] ์ˆซ์ž ์ง๊ฟ

๋ฌธ์ œ ์„ค๋ช… ๋ฌธ์ œ ํ’€์ด ๊ณผ์ • ์ฒซ ๋ฒˆ์งธ ํ’€์ด: ์‹œ๊ฐ„ ์ดˆ๊ณผ from collections import Counter def solution(X, Y): answer = '' inter = list(set(X) & set(Y)) s = [] x = sorted(X, reverse = True) y = sorted(Y, reverse = True) cnt_x = Counter(x) cnt_y = Counter(y) if len(inter) == 0: return '-1' else: for i in sorted(inter, reverse = True): answer += str(i * min(cnt_x[i], cnt_y[i])) if int(answer) == 0: answer = '0' return answer ..

Coding test 2022.12.12

[Programmers] ์‚ผ์ด์‚ฌ

๋ฌธ์ œ ์„ค๋ช… ๋ฌธ์ œํ’€์ด ๊ณผ์ • combination: ์ง€์ • ๊ฐœ์ˆ˜์”ฉ ์ค‘๋ณต ๋ฐฐ์—ด ์—†๋Š” ์กฐํ•ฉ ๋งŒ๋“ค์–ด์ฃผ๋Š” ํ•จ์ˆ˜ combination์„ ์ด์šฉํ•˜์—ฌ ํ•ด๋‹น ๋ฆฌ์ŠคํŠธ์—์„œ 3๊ฐœ์”ฉ ์ค‘๋ณต ์—†๋Š” ์กฐํ•ฉ์„ ๋งŒ๋“ค์–ด ์คŒ list(map(sum, comb)): ์กฐํ•ฉ์˜ sum์„ map์„ ์ด์šฉํ•˜์—ฌ ์ง„ํ–‰ํ•˜์—ฌ list๋กœ ๋งŒ๋“ค์–ด์คŒ answer์— ํ•ฉ์ด 0์ธ ๋ถ€๋ถ„์„ countํ•˜์—ฌ ๋”ํ•ด์คŒ from itertools import combinations def solution(number): answer = 0 comb = list(combinations(number, 3)) cnt = list(map(sum, comb)) answer += cnt.count(0) return answer ์ด๊ฑด ์ง„์งœ ์ž˜ ์งฐ๋‹ค. ๋งŒ์กฑํ•˜๋Š” ์ฝ”๋“œ - coding test url: h..

Coding test 2022.12.12
728x90