A person wants to determine the most expensive computer keyboard and USB drive that can be purchased with a give budget. Given price lists for keyboards and USB drives and a budget, find the cost to buy them. If it is not possible to buy both items, return -1 ....
See the full description of the problem Electronics Shop
We can sort and compare all pairs. If a pair is > max and <= s then we set it as the new max. Then we eturn max after checking all pairs.
Time Complexity: O(n * m) //Iterate over both arrays
Space Complexity: O(1) //No additional memory used