Sort by

recency

|

2396 Discussions

|

  • + 0 comments

    Here is my Python code! We first find all possible combinations of keyboards and drives and then find the largest sum of those. I appended -1 so if there is no combination within budget, it returns -1.

    def getMoneySpent(keyboards, drives, b):
        possible = list(itertools.product(*[keyboards, drives]))
        for a in range(len(possible)):
            possible[a] = sum(possible[a])
        inbudget = [x for x in possible if x <= b]
        inbudget.append(-1)
        return max(inbudget)
    
  • + 1 comment

    What is the best time complexity that can be achieved?

  • + 0 comments

    Here is my c++ solution, you can find the video here : https://youtu.be/yC-TXToDbD0

    int getMoneySpent(vector<int> keyboards, vector<int> drives, int b) {
        int ans = -1;
        for(int k : keyboards){
            for(int d : drives){
                if(k + d > ans && k + d <= b) ans = k + d;
            }
        }
        return ans;
    }
    
  • + 0 comments

    Very simple python solution here

    def getMoneySpent(keyboards, drives, b):
        sortedKeyBoards = sorted(keyboards, reverse=True)
        drives = sorted(drives, reverse=True)
        sumMax = 0
        
        for i in range(len(sortedKeyBoards)):
            for j in range(len(drives)):
                sumTemp = sortedKeyBoards[i] + drives[j]
                if ( sumTemp >= sumMax and sumTemp <= b):
                    sumMax = sumTemp
                    
        return -1 if sumMax == 0 else sumMax
    
  • + 0 comments

    I run a car dealership shop in arizona that sells new and used cars. I want to apply this code on my website. I want to sue this code on my magento based website built with magento 2.1 version