https://programmers.co.kr/learn/courses/30/lessons/42840
Code
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
def solution(answers):
answer = []
p1 = lambda idx: idx % 5 + 1
def p2(idx):
if idx % 2 == 0:
return 2
else:
i = idx % 8
if i == 1:
return 1
elif i == 3:
return 3
elif i == 5:
return 4
elif i == 7:
return 5
def p3(idx):
i = idx % 10
if i < 2:
return 3
elif i < 4:
return 1
elif i < 6:
return 2
elif i < 8:
return 4
elif i < 10:
return 5
n_problem = len(answers)
a1 = [p1(idx) for idx in range(n_problem)]
a2 = [p2(idx) for idx in range(n_problem)]
a3 = [p3(idx) for idx in range(n_problem)]
s1, s2, s3 = 0, 0, 0
for idx, answer in enumerate(answers):
if answer == a1[idx]:
s1 += 1
if answer == a2[idx]:
s2 += 1
if answer == a3[idx]:
s3 += 1
m_s = max(s1, s2, s3)
answer = []
for i, s in enumerate([s1, s2, s3]):
if s == m_s:
answer.append(i+1)
return answer
Complexity
$O(n)$
- $n$ = len(answers)
PREVIOUSEtc