Post

๐Ÿข ๊ฐœ์ธ์ •๋ณด ์ˆ˜์ง‘ ์œ ํšจ๊ธฐ๊ฐ„

1. ๋ฌธ์ œ ๋งํฌ

2023 KAKAO BLIND RECRUITMENT: ๊ฐœ์ธ์ •๋ณด ์ˆ˜์ง‘ ์œ ํšจ๊ธฐ๊ฐ„


2. ์ฝ”๋“œ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""
๊ฐœ์ธ์ •๋ณด ์ˆ˜์ง‘ ์œ ํšจ๊ธฐ๊ฐ„

๐Ÿ’› ๋ฌธ์ œ
๊ณ ๊ฐ์˜ ์•ฝ๊ด€ ๋™์˜๋ฅผ ์–ป์–ด์„œ ์ˆ˜์ง‘๋œ 1~n๋ฒˆ์œผ๋กœ ๋ถ„๋ฅ˜๋˜๋Š” ๊ฐœ์ธ์ •๋ณด n๊ฐœ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.
์•ฝ๊ด€ ์ข…๋ฅ˜๋Š” ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ์žˆ์œผ๋ฉฐ ๊ฐ ์•ฝ๊ด€๋งˆ๋‹ค ๊ฐœ์ธ์ •๋ณด ๋ณด๊ด€ ์œ ํšจ๊ธฐ๊ฐ„์ด ์ •ํ•ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.
๋‹น์‹ ์€ ๊ฐ ๊ฐœ์ธ์ •๋ณด๊ฐ€ ์–ด๋–ค ์•ฝ๊ด€์œผ๋กœ ์ˆ˜์ง‘๋๋Š”์ง€ ์•Œ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

์ˆ˜์ง‘๋œ ๊ฐœ์ธ์ •๋ณด๋Š” ์œ ํšจ๊ธฐ๊ฐ„ ์ „๊นŒ์ง€๋งŒ ๋ณด๊ด€ ๊ฐ€๋Šฅํ•˜๋ฉฐ, ์œ ํšจ๊ธฐ๊ฐ„์ด ์ง€๋‚ฌ๋‹ค๋ฉด ๋ฐ˜๋“œ์‹œ ํŒŒ๊ธฐํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด, A๋ผ๋Š” ์•ฝ๊ด€์˜ ์œ ํšจ๊ธฐ๊ฐ„์ด 12 ๋‹ฌ์ด๊ณ , 2021๋…„ 1์›” 5์ผ์— ์ˆ˜์ง‘๋œ ๊ฐœ์ธ์ •๋ณด๊ฐ€ A์•ฝ๊ด€์œผ๋กœ ์ˆ˜์ง‘๋˜์—ˆ๋‹ค๋ฉด
ํ•ด๋‹น ๊ฐœ์ธ์ •๋ณด๋Š” 2022๋…„ 1์›” 4์ผ๊นŒ์ง€ ๋ณด๊ด€ ๊ฐ€๋Šฅํ•˜๋ฉฐ 2022๋…„ 1์›” 5์ผ๋ถ€ํ„ฐ ํŒŒ๊ธฐํ•ด์•ผ ํ•  ๊ฐœ์ธ์ •๋ณด์ž…๋‹ˆ๋‹ค.
๋‹น์‹ ์€ ์˜ค๋Š˜ ๋‚ ์งœ๋กœ ํŒŒ๊ธฐํ•ด์•ผ ํ•  ๊ฐœ์ธ์ •๋ณด ๋ฒˆํ˜ธ๋“ค์„ ๊ตฌํ•˜๋ ค ํ•ฉ๋‹ˆ๋‹ค.

๋ชจ๋“  ๋‹ฌ์€ 28์ผ๊นŒ์ง€ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค.

์˜ค๋Š˜ ๋‚ ์งœ๋ฅผ ์˜๋ฏธํ•˜๋Š” ๋ฌธ์ž์—ด today, ์•ฝ๊ด€์˜ ์œ ํšจ๊ธฐ๊ฐ„์„ ๋‹ด์€ 1์ฐจ์› ๋ฌธ์ž์—ด ๋ฐฐ์—ด terms์™€
์ˆ˜์ง‘๋œ ๊ฐœ์ธ์ •๋ณด์˜ ์ •๋ณด๋ฅผ ๋‹ด์€ 1์ฐจ์› ๋ฌธ์ž์—ด ๋ฐฐ์—ด privacies๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค.

์ด๋•Œ ํŒŒ๊ธฐํ•ด์•ผ ํ•  ๊ฐœ์ธ์ •๋ณด์˜ ๋ฒˆํ˜ธ๋ฅผ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ 1์ฐจ์› ์ •์ˆ˜ ๋ฐฐ์—ด์— ๋‹ด์•„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด ์ฃผ์„ธ์š”.

๐Ÿงก ์ œํ•œ ์‚ฌํ•ญ
today๋Š” "YYYY.MM.DD" ํ˜•ํƒœ๋กœ ์˜ค๋Š˜ ๋‚ ์งœ๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.
1 โ‰ค terms์˜ ๊ธธ์ด โ‰ค 20
    terms์˜ ์›์†Œ๋Š” "์•ฝ๊ด€ ์ข…๋ฅ˜ ์œ ํšจ๊ธฐ๊ฐ„" ํ˜•ํƒœ์˜ ์•ฝ๊ด€ ์ข…๋ฅ˜์™€ ์œ ํšจ๊ธฐ๊ฐ„์„ ๊ณต๋ฐฑ ํ•˜๋‚˜๋กœ ๊ตฌ๋ถ„ํ•œ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค.
    ์•ฝ๊ด€ ์ข…๋ฅ˜๋Š” A~Z์ค‘ ์•ŒํŒŒ๋ฒณ ๋Œ€๋ฌธ์ž ํ•˜๋‚˜์ด๋ฉฐ, terms ๋ฐฐ์—ด์—์„œ ์•ฝ๊ด€ ์ข…๋ฅ˜๋Š” ์ค‘๋ณต๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
    ์œ ํšจ๊ธฐ๊ฐ„์€ ๊ฐœ์ธ์ •๋ณด๋ฅผ ๋ณด๊ด€ํ•  ์ˆ˜ ์žˆ๋Š” ๋‹ฌ ์ˆ˜๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ์ •์ˆ˜์ด๋ฉฐ, 1 ์ด์ƒ 100 ์ดํ•˜์ž…๋‹ˆ๋‹ค.
1 โ‰ค privacies์˜ ๊ธธ์ด โ‰ค 100
    privacies[i]๋Š” i+1๋ฒˆ ๊ฐœ์ธ์ •๋ณด์˜ ์ˆ˜์ง‘ ์ผ์ž์™€ ์•ฝ๊ด€ ์ข…๋ฅ˜๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.
    privacies์˜ ์›์†Œ๋Š” "๋‚ ์งœ ์•ฝ๊ด€ ์ข…๋ฅ˜" ํ˜•ํƒœ์˜ ๋‚ ์งœ์™€ ์•ฝ๊ด€ ์ข…๋ฅ˜๋ฅผ ๊ณต๋ฐฑ ํ•˜๋‚˜๋กœ ๊ตฌ๋ถ„ํ•œ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค.
    ๋‚ ์งœ๋Š” "YYYY.MM.DD" ํ˜•ํƒœ์˜ ๊ฐœ์ธ์ •๋ณด๊ฐ€ ์ˆ˜์ง‘๋œ ๋‚ ์งœ๋ฅผ ๋‚˜ํƒ€๋‚ด๋ฉฐ, today ์ด์ „์˜ ๋‚ ์งœ๋งŒ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค.
    privacies์˜ ์•ฝ๊ด€ ์ข…๋ฅ˜๋Š” ํ•ญ์ƒ terms์— ๋‚˜ํƒ€๋‚œ ์•ฝ๊ด€ ์ข…๋ฅ˜๋งŒ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค.
today์™€ privacies์— ๋“ฑ์žฅํ•˜๋Š” ๋‚ ์งœ์˜ YYYY๋Š” ์—ฐ๋„, MM์€ ์›”, DD๋Š” ์ผ์„ ๋‚˜ํƒ€๋‚ด๋ฉฐ ์ (.) ํ•˜๋‚˜๋กœ ๊ตฌ๋ถ„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
    2000 โ‰ค YYYY โ‰ค 2022
    1 โ‰ค MM โ‰ค 12
    MM์ด ํ•œ ์ž๋ฆฟ์ˆ˜์ธ ๊ฒฝ์šฐ ์•ž์— 0์ด ๋ถ™์Šต๋‹ˆ๋‹ค.
    1 โ‰ค DD โ‰ค 28
    DD๊ฐ€ ํ•œ ์ž๋ฆฟ์ˆ˜์ธ ๊ฒฝ์šฐ ์•ž์— 0์ด ๋ถ™์Šต๋‹ˆ๋‹ค.
ํŒŒ๊ธฐํ•ด์•ผ ํ•  ๊ฐœ์ธ์ •๋ณด๊ฐ€ ํ•˜๋‚˜ ์ด์ƒ ์กด์žฌํ•˜๋Š” ์ž…๋ ฅ๋งŒ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค.

๐Ÿ’š ์ž…์ถœ๋ ฅ
today	        terms	                privacies	                                                                        result
"2022.05.19"	["A 6", "B 12", "C 3"]	["2021.05.02 A", "2021.07.01 B", "2022.02.19 C", "2022.02.20 C"]	                [1, 3]
"2020.01.01"	["Z 3", "D 5"]	        ["2019.01.01 D", "2019.11.15 Z", "2019.08.02 D", "2019.07.01 D", "2018.12.28 Z"]    [1, 4, 5]
"""


def solution(today, terms, privacies):
    answer = []

    y, m, d = today.split(".")
    y, m = int(y), int(m)

    # ์˜ค๋Š˜ ๋‚ ์งœ๋ฅผ ์˜๋ฏธํ•˜๋Š” ๋ฌธ์ž์—ด today, ์•ฝ๊ด€์˜ ์œ ํšจ๊ธฐ๊ฐ„์„ ๋‹ด์€ 1์ฐจ์› ๋ฌธ์ž์—ด ๋ฐฐ์—ด terms
    # ์ˆ˜์ง‘๋œ ๊ฐœ์ธ์ •๋ณด์˜ ์ •๋ณด๋ฅผ ๋‹ด์€ 1์ฐจ์› ๋ฌธ์ž์—ด ๋ฐฐ์—ด privacies

    # input ๊ฐ’๋“ค์„ ์ „์ฒ˜๋ฆฌ ํ•ด์ค€๋‹ค ์˜ˆ์˜๊ฒŒ ๋‹ค์‹œ split ํ•ด์„œ ์ƒˆ ๋ฐฐ์—ด ์•ˆ์œผ๋กœ ๋„ฃ์–ด์ค€๋‹ค
    terms_temp = []

    for i in range(len(terms)):
        a, b = terms[i].split(" ")
        # [['A', 6], ['B', 12], ['C', 3]]
        terms_temp.append([a, int(b)])

    privacies_temp = []
    for i in range(len(privacies)):
        a, b = privacies[i].split(" ")
        y, m, d = a.split(".")
        # [[2021, 5, 2, 'A'], [2021, 7, 1, 'B'], [2022, 2, 19, 'C'], [2022, 2, 20, 'C']]
        privacies_temp.append([int(y), int(m), d, b])

    new_privacies_temp = [[] for _ in range(len(privacies))]
    # ์œ ํšจ ๊ธฐ๊ฐ„ ์ž…๋ ฅํ•˜๊ธฐ
    for i in range(len(terms_temp)):
        for j in range(len(privacies_temp)):
            temp = []
            # ์•ฝ๊ด€ ์ข…๋ฅ˜ ๋น„๊ตํ•˜๊ธฐ
            if terms_temp[i][0] == privacies_temp[j][3]:
                # ์•ฝ๊ด€ ์œ ํšจ ๊ธฐ๊ด€ (๋‹ฌ) ๋”ํ•˜๊ธฐ
                yy = privacies_temp[j][1] + terms_temp[i][1]
                # 12๊ฐœ์›” (1๋…„) ์„ ์ง€๋‚œ๋‹ค๋ฉด ๋…„๋„ +1
                if yy > 12:
                    if (yy % 12 == 0):
                        yyy = yy // 12 - 1
                        privacies_temp[j][0] += yyy
                        yy = 12
                    else:
                        yyy = yy // 12
                        privacies_temp[j][0] += yyy
                        yy -= 12 * yyy

                temp = [privacies_temp[j][0], str(
                    yy).zfill(2), privacies_temp[j][2]]
                # ['2021.11.02', '2022.7.01', '2022.5.19', '2022.5.20']
                print(temp)
                new_privacies_temp[j] = ".".join(map(str, temp))

    # ์˜ค๋Š˜ ๋‚ ์งœ์™€ ๋น„๊ตํ•˜๊ธฐ
    for i in range(len(new_privacies_temp)):
        if today >= new_privacies_temp[i]:
            answer.append(i+1)

    return answer

  • ์ •ํ™•์„ฑ

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    
      ํ…Œ์ŠคํŠธ 1 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 2 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.4MB)
      ํ…Œ์ŠคํŠธ 3 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.4MB)
      ํ…Œ์ŠคํŠธ 4 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.4MB)
      ํ…Œ์ŠคํŠธ 5 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.4MB)
      ํ…Œ์ŠคํŠธ 6 ใ€‰	ํ†ต๊ณผ (0.09ms, 10.4MB)
      ํ…Œ์ŠคํŠธ 7 ใ€‰	ํ†ต๊ณผ (0.09ms, 10.4MB)
      ํ…Œ์ŠคํŠธ 8 ใ€‰	ํ†ต๊ณผ (0.12ms, 10.5MB)
      ํ…Œ์ŠคํŠธ 9 ใ€‰	ํ†ต๊ณผ (0.22ms, 10.6MB)
      ํ…Œ์ŠคํŠธ 10 ใ€‰ํ†ต๊ณผ (0.22ms, 10.5MB)
      ํ…Œ์ŠคํŠธ 11 ใ€‰ํ†ต๊ณผ (0.23ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 12 ใ€‰ํ†ต๊ณผ (0.44ms, 10.4MB)
      ํ…Œ์ŠคํŠธ 13 ใ€‰ํ†ต๊ณผ (0.43ms, 10.4MB)
      ํ…Œ์ŠคํŠธ 14 ใ€‰ํ†ต๊ณผ (0.29ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 15 ใ€‰ํ†ต๊ณผ (0.28ms, 10.5MB)
      ํ…Œ์ŠคํŠธ 16 ใ€‰ํ†ต๊ณผ (0.58ms, 10.5MB)
      ํ…Œ์ŠคํŠธ 17 ใ€‰ํ†ต๊ณผ (0.97ms, 10.5MB)
      ํ…Œ์ŠคํŠธ 18 ใ€‰ํ†ต๊ณผ (1.04ms, 10.5MB)
      ํ…Œ์ŠคํŠธ 19 ใ€‰ํ†ต๊ณผ (0.53ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 20 ใ€‰ํ†ต๊ณผ (0.54ms, 10.4MB)
    


3. ํ•ด์„ค

์ž…๋ ฅ๊ฐ’ ใ€‰ โ€œ2020.12.17โ€, [โ€œA 12โ€], [โ€œ2010.01.01 Aโ€, โ€œ2019.12.17 Aโ€]

๊ธฐ๋Œ“๊ฐ’ ใ€‰ [1, 2]

๋ฐ˜๋ก€๊ฐ€ ์žˆ์—ˆ๋‹ค.. 12์˜ ๋ฐฐ์ˆ˜ ์ผ ๋•Œ๋งŒ 12๋กœ ๋‹ฌ์„ ์ง€์ •ํ•ด์ฃผ๊ณ  ๋…„๋„๋Š” ๋ชซ์—์„œ 1์„ ๋นผ์ค˜์„œ ๋”ํ•ด์คฌ๋‹ค

์ผ์€ ํ•„์š” ์—†์œผ๋‹ˆ๊นŒ ๋…„, ๋‹ฌ๋งŒ int ๋กœ ํฌ๊ธฐ ๋น„๊ต ํ•ด์ฃผ๊ณ  ๋งˆ์ง€๋ง‰์— ๋ฌธ์ž์—ด๋กœ ํ•ฉ์ณ์ค€ ๋‹ค์Œ ํฌ๊ธฐ๋ฅผ ๋น„๊ตํ•œ๋‹ค

This post is licensed under CC BY 4.0 by the author.