Algorithm/프로그래머스 예제
[코딩테스트] K번째 수
AI_Dev_Youngchan
2021. 10. 27. 11:50
# 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
비교적 쉬웠던 문제였던 것 같다. 숫자를 정렬하고 자릿수만 잘 찾아서 배열안에 있는 값을 뽑아주면 해결되는 문제였다.