티스토리 뷰

 

 

 

https://programmers.co.kr/learn/courses/30/lessons/42748

 

코딩테스트 연습 - K번째수

[1, 5, 2, 6, 3, 7, 4] [[2, 5, 3], [4, 4, 1], [1, 7, 3]] [5, 6, 3]

programmers.co.kr

 

 

문제

 

 

풀이

function solution(array, commands) {
  const answer = []
  commands.map((command) => {
    const i = command[0]
    const j = command[1]
    const k = command[2]
    answer.push(array.slice(i - 1, j).sort((a, b) => a - b)[k - 1])
  })
  return answer
}

 


 

 

링크
«   2025/02   »
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
Total
Today
Yesterday