You are viewing a single comment's thread. Return to all comments →
JS solution:
function getMoneySpent(keyboards, drives, b) { /* * Write your code here. */ keyboards.sort((a, b) => a - b) drives.sort((a, b) => b - a) let maxPrice = -1 let kIndex = 0 let dIndex = 0 while(kIndex < keyboards.length && dIndex < drives.length) { let combinedCost = keyboards[kIndex] + drives[dIndex] if (combinedCost > b) { dIndex++ continue } kIndex++ if (combinedCost > maxPrice) { maxPrice = combinedCost } } return maxPrice }
Seems like cookies are disabled on this browser, please enable them to open this website
Electronics Shop
You are viewing a single comment's thread. Return to all comments →
JS solution: