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.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Implementation
  4. Electronics Shop
  5. Discussions

Electronics Shop

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 1989 Discussions, By:

recency

Please Login in order to post a comment

  • kevocodes
    12 hours ago+ 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|
    Permalink
  • rohitKonnur
    2 days ago+ 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|
    Permalink
  • dipakmandaljio41
    2 days ago+ 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|
    Permalink
  • dggrc
    4 days ago+ 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|
    Permalink
  • kartikmishra686
    4 days ago+ 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;
    }
    

    }

    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy