• + 4 comments

    Your solution is still O(n*m).

    Suppose I give you prices of keyboards and drives such that if you purchased the highest cost keyboard and the highest cost usb, it would still be less than your spending amount. Your algorithm would go through every pairing of keyboards and usbs, which is the same as brute forcing.