• + 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);
    }