We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
For JS, remember to use BigInt, otherwise, test case 11 will be failed.
functionboardCutting(cost_y,cost_x){// Write your code hereletsum=BigInt(0);letsortedCostX=[...cost_x].toSorted((a,b)=>b-a);letsortedCostY=[...cost_y].toSorted((a,b)=>b-a);letpx=0,py=0;while(px<sortedCostX.length&&py<sortedCostY.length){if(sortedCostX[px]>sortedCostY[py]){sum+=BigInt(py+1)*BigInt(sortedCostX[px]);px++;}else{sum+=BigInt(px+1)*BigInt(sortedCostY[py]);py++;}}while(px<sortedCostX.length){sum+=BigInt(py+1)*BigInt(sortedCostX[px]);px++;}while(py<sortedCostY.length){sum+=BigInt(px+1)*BigInt(sortedCostY[py]);py++;}returnsum%BigInt(10**9+7);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Cutting Boards
You are viewing a single comment's thread. Return to all comments →
For JS, remember to use BigInt, otherwise, test case 11 will be failed.