# array commands return
#[1, 5, 2, 6, 3, 7, 4] [[2, 5, 3], [4, 4, 1], [1, 7, 3]] [5, 6, 3]
array = [1,5,2,6,3,7,4]
commands = [[2,5,3],[4,4,1],[1,7,3]]
def solution(array, commands):
answer = []
for i in range(len(commands)) :
temp = array[commands[i][0]-1 : commands[i][1]]
#print(temp)
sort = sorted(temp)
#print(sort)
answer.append(sort[commands[i][2]-1])
return answer
비교적 쉬웠던 문제였던 것 같다. 숫자를 정렬하고 자릿수만 잘 찾아서 배열안에 있는 값을 뽑아주면 해결되는 문제였다.
'Algorithm > 프로그래머스 예제' 카테고리의 다른 글
[코딩테스트] 전화번호 목록 (0) | 2021.10.27 |
---|---|
[코딩테스트] 완주하지 못한 선수 (0) | 2021.10.27 |