/**
* @param {number[]} seats
* @param {number[]} students
* @return {number}
*/varminMovesToSeat=function (seats,students){letres=0seats.sort((a,b)=>b-a)students.sort((a,b)=>b-a)for (leti=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])}returnres};
Top comments (0)
Subscribe
We're a place where coders share, stay up-to-date and grow their careers.
Top comments (0)