문제
https://school.programmers.co.kr/learn/courses/30/lessons/42748
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
< K번째수 >
문제 풀이 (Java)
import java.util.*;
class Solution {
public int[] solution(int[] array, int[][] commands) {
int[] answer = new int[commands.length];
for (int i = 0; i < commands.length; i++) {
int temp[] = new int[commands[i][1] + 1 - commands[i][0]];
for (int j = commands[i][0] - 1; j < commands[i][1]; j++) {
temp[j - (commands[i][0] - 1)] = array[j];
}
Arrays.sort(temp);
answer[i] = temp[commands[i][2] - 1];
}
return answer;
}
}
commands를 순회하며 다음 과정을 거친다.
1. i번째 숫자부터 j번째 숫자까지 자르기
2. 자른 배열을 정렬
3. k번째 있는 수를 answer에 저장
최종 answer을 반환한다.

출처: 프로그래머스 코딩 테스트 연습,
https://school.programmers.co.kr/learn/challenges
'🌞Algorithm > 🔥programmers' 카테고리의 다른 글
| [programmers] 완주하지 못한 선수 (0) | 2026.07.30 |
|---|---|
| [programmers] 디스크 컨트롤러 (0) | 2026.07.29 |
| [programmers] 이중우선순위큐 (0) | 2026.07.27 |
| [programmers] 베스트앨범 (0) | 2026.07.24 |
| [programmers] 정수 삼각형 (0) | 2026.07.22 |