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