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.
staticintgetMoneySpent(int[]keyboards,int[]drives,intb){intmaxBudget=-1;// Initialize to -1 to handle cases where no valid combination is found// Iterate over each keyboard pricefor(inti=0;i<keyboards.length;i++){// Iterate over each drive pricefor(intj=0;j<drives.length;j++){inttotalCost=keyboards[i]+drives[j];// Check if the total cost is within the budgetif(totalCost<=b){// Update maxBudget if this combination is bettermaxBudget=Math.max(maxBudget,totalCost);}}}returnmaxBudget;}
Cookie support is required to access HackerRank
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 →
JavaSolution