Amazon VO Interview Question: Find a Product Pair That Best Uses a Gift Coupon

19 Views
No Comments

Suppose you are given 2 unordered lists of Amazon products with product id, price and a gift coupon worth S amount.

Can you write a function to find 1 product from each list which can best utilize the gift coupon (not more than the value)?

You can write a function in the programming language of your choice.

Input: (a: 10, b: 2, c: 5, d: 8) (x: 20, y: 15, z: 10), S: 16

Result: => (c: 5, z: 10)

Return null if no price < S.

This problem asks you to choose one product from each of two unordered product lists so that the combined price does not exceed the coupon value S and is as close to S as possible. A common approach is to sort or index one list by price, then scan the other list and use a hash map or binary search to find the best partner for each item within the remaining budget. In the example, prices 5 and 10 produce 15, which is the best valid total under 16. If no valid pair exists, return null.

END
 0