Post

ํฐ ์ˆ˜ lv0

๐ŸŒˆ๋ฌธ์ œ ๋งํฌ

๋ฌธ์ œ ์„ค๋ช…: arr = [1, 5, 2, 6, 3, 7, 4] ๋ฐฐ์—ด์ด ์žˆ๋‹ค ๋‹ค์Œ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜์—ฌ ์ถœ๋ ฅ๊ฐ’์„ [5, 6, 3]์œผ๋กœ ๋งŒ๋“ค์–ด๋ผ

  1. arr์˜ 2๋ฒˆ์งธ์—์„œ 5๋ฒˆ์งธ ๊นŒ์ง€ ๋นผ๋‚ด๊ณ  ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•ด์„œ ๋นผ๋‚ธ 3๋ฒˆ์งธ ์ˆซ์ž โ€“> 5
  2. arr์˜ 4๋ฒˆ์งธ์—์„œ 4๋ฒˆ์งธ ๊นŒ์ง€ ๋นผ๋‚ด๊ณ  ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•ด์„œ ๋นผ๋‚ธ 1๋ฒˆ์งธ ์ˆซ์ž โ€“> 6
  3. arr์˜ 1๋ฒˆ์งธ๋ถ€ํ„ฐ 7๋ฒˆ์งธ ๊นŒ์ง€ ๋นผ๋‚ด๊ณ  ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•ด์„œ ๋นผ๋‚ธ 3๋ฒˆ์งธ ์ˆซ์ž โ€“> 3
    โ˜…์•„๋ž˜ com์€ 1, 2, 3์˜ ์กฐ๊ฑด์„ ๋‚˜ํƒ€๋‚ธ ๊ฒƒ์ด๋‹ค
    โ€“> ์ด ์กฐ๊ฑด์— ๋”ฐ๋ผ ๊ฐ๊ฐ ๊ฐ’์ด 5, 6, 3์œผ๋กœ return๋œ๋‹ค
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
arr = [1, 5, 2, 6, 3, 7, 4]
com = [
    [2, 5, 3], # com[0]
     [4, 4, 1], # com[1]
      [1, 7, 3] # com[2]
    ]
return --> 5, 6, 3

 

-----------------------------------------------------------------------

def solution(arr, com):
    answer = []
    for c in com:
        s_a = arr[c[0]-1 : c[1]]
        s_a.sort()
        answer.append(s_a[c[2]-1])
    return answer

print(solution(arr, com))

# ์ถœ๋ ฅ๊ฒฐ๊ณผ
[5, 6, 3]
This post is licensed under CC BY 4.0 by the author.
3D GIF