/**
* @param {number[]} seats
* @param {number[]} students
* @return {number}
*/
var minMovesToSeat = function (seats, students) {
let res = 0
seats.sort((a, b) => b - a)
students.sort((a, b) => b - a)
for (let i = 0; i < seats.length; i++) {
//the cost of moving a student is the absolute difference between their current position and the target seat position
//pair the closest seats with the closest students.
res += Math.abs(seats[i] - students[i])
}
return res
};
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)