A new semester has begun. Hyunsoo was so excited to meet his new mate.
There are N students in Hyunsoo’s class.
In order to assign class numbers to the class, the teacher placed the class in a row on the playground, starting with the tallest student. Class numbers are numbered from 1 to N, starting with the smallest student first. Hyunsu is taller than his partner. However, Hyunsoo wanted to get the number in front of him, so he changed seats with his partner. The teacher was unaware of this and numbered the students in the order in which they stood.
Write a program that prints the number Hyun-soo and his partner received in order when given information about the height of the students standing in a line in the class who swapped seats.
9
120 125 152 130 135 135 143 127 160
6
120 130 150 150 130 150
On the first line, print the half number of the hyung and the half number of the partner in that order.
3 8 //Key information 152 is Hyunsu, and 127 is Hyunsu's partner.
3 5
sort
with speard ...
function solution(arr) {
let answer = [];
let expected = [...arr].sort((a, b) => a - b);
for (let i = 0; i < arr.length; i++) {
if (expected[i] !== arr[i]) answer.push(i + 1);
}
return answer;
}
sort
with speard slice()
function solution(arr) {
let answer = [];
let expected = arr.slice().sort((a, b) => a - b);
for (let i = 0; i < arr.length; i++) {
if (expected[i] !== arr[i]) answer.push(i + 1);
}
return answer;
}