Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Stefanacef/4a7a968618945c86148229e8ea6afd8c to your computer and use it in GitHub Desktop.
Save Stefanacef/4a7a968618945c86148229e8ea6afd8c to your computer and use it in GitHub Desktop.
Solution for "Electronics Shop" in Hackerrank
const b= 10;
const keyboards=[3, 1];
const drives=[5, 2, 8]
function getMoneySpent(keyboards, drives, b) {
let arr=[];
for(let i=0;i<keyboards.length;i++){
for(let j=0;j<drives.length;j++){
if(keyboards[i]+drives[j]<=b)
arr.push(keyboards[i]+drives[j])
}
}
arr.sort((a,b)=>a-b)
if(arr.length==0){
return (-1)
}else{
return Math.max(...arr)
}
}
console.log(getMoneySpent(keyboards, drives, b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment