hackerrank electronics shop problem JavaScript solution by Subrat Dash

preview_player
Показать описание
hackerrank electronics shop problem JavaScript solution by Subrat Dash.

A person wants to determine the most expensive computer keyboard and USB drive that can be purchased with a give budget. Given price lists for keyboards and USB drives and a budget, find the cost to buy them. If it is not possible to buy both items, return -1.

GitHub Code Link :
Рекомендации по теме
Комментарии
Автор

Can you make more videos on Javascript tutorial and dsa solution of Hacker rank

jituop
Автор

*Here is my solution*
but runtime is high on this one

function getMoneySpent(keyboards, drives, b) {
let max = new Set([-1]);
for (let i = 0; i < keyboards.length; i++) {
for (let j = 0; j < drives.length; j++) {
let sum = keyboards[i] + drives[j];
if (sum <= b) max.add(sum);
}
}
return Math.max(...max);
}

avinash
Автор

why you set the max to -1 and not 0, can u explain that part please

waleedahmed
join shbcf.ru