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.
Electronics Shop
Electronics Shop
+ 0 comments JS solution
function getMoneySpent(keyboards, drives, b) { if(Math.min(...keyboards)+Math.min(...drives) > b){ return -1 } const inBudget = []; for(let i = 0; i < keyboards.length; i++){ for(let j = 0; j < drives.length; j++){ const sum = keyboards[i]+drives[j]; if(sum <= b){ inBudget.push(sum); } } } return Math.max(...inBudget); }
+ 0 comments In python 3
def getMoneySpent(keyboards, drives, b): l1=[] for i in keyboards: for j in drives: if i+j<=b: l1.append(i+j) if len(l1)==0:return -1 return max(l1)
+ 0 comments //my js solution function getMoneySpent(keyboards, drives, b) { let sum = 0; let budget = [] for (let i = 0; i < keyboards.length; i++) { for (let j = 0; j < drives.length; j++) { sum = keyboards[i] + drives[j] if (sum <= b) { budget.push(sum) } } } let result = Math.max(...budget) if (budget.length === 0) { return -1 } else { return result } }
+ 0 comments function getMoneySpent(keyboards, drives, b) { /* * I know the solution is pretty straight forward, but I like my formating the best */ let mostExpensivePurchase = -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 && sum > mostExpensivePurchase) mostExpensivePurchase = sum; } } return mostExpensivePurchase; }
+ 0 comments Javascript Simple Solution
function getMoneySpent(keyboards, drives, b) { let m = keyboards.length; let n = drives.length; let val = 0; for(let i = 0; i < m; i++){ for(let j = 0; j < n; j++){ if(keyboards[i]+drives[j] <= b && keyboards[i]+drives[j] > val){ val = keyboards[i]+drives[j]; } } } if(val == 0){ return -1; } else{
return val; }
}
Load more conversations
Sort 1989 Discussions, By:
Please Login in order to post a comment