Yazı Kafası Site Logosu
HackerRank Road Repair Solution Javascript
HackerRank Road Repair Solution Javascript 132203

Question IMG  Question IMG-2

function getMinCost(crew_id, job_id) {

  let cost = 0;

  const sortedCrew = crew_id.sort((a, b) => a - b);

  const sortedJob = job_id.sort((a, b) => a - b);

  for (let i = 0; i < crew_id.length; i++) {

    cost += Math.abs(sortedCrew[i] - sortedJob[i]);

  }

  return cost;

}

2311 129601

Benzer Yazılar