This is a verified interview question from Amazon. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Allocate limited inventory items based on priority algorithm - Amazon Online Assessment" covers key patterns like Arrays.
"Allocate limited inventory items based on priority algorithm. During a flash sale on Amazon, customers submit requests for a limited quantity of a product. Each of the request includes: *[customerId, quantity, bidAmount, timestamp]*. Items are allocated using these rules: * Higher bids get priority. * If multiple customers have the same bid, allocate items in a round-robin manner based on the earliest timestamp until all of the inventory is allocated. * A customer gets one item per round until their request is fulfilled. Return the *IDs* of customers who received no items. **Note:** Round-robin allocation means cycling through the tied customers in order of their timestamps, granting exactly one item to each customer per cycle, until either the inventory runs out or all their requested quantities are fulfilled. ### Example **Input:** `requests = [[1, 5, 5, 0], [2, 7, 8, 1], [3, 7, 5, 1], [4, 10, 3, 3]]` `totalInventory = 18` **Output:** `[4]` **Explanation:** The first three requests have a higher bidding amount than 4th request, and the total quantity requested in the first three requests is 19, whereas the available inventory is 18, so only one left without any allocation will be customer ID 4. ### Function Description Complete the function *getUnfulfilledCustomers* with the following parameters: * `int requests[requests[0],...requests[n-1]]`: 2D array of integers where each row is [customerId, quantity, bidAmount, timestamp] * `int totalInventory`: an integer, the total number of items available for allocation ### Returns * `int[]`: a list of customer IDs who did not receive any items, sorted in ascending order"
Join thousands of developers practicing for Amazon.