Amazon OA真题揭秘:高价优先 + 轮询分配的库存争夺战 – OA 代写 – OA 代做 – 面试辅助

Problem Description

Allocate limited inventory items based on a priority algorithm.

During a flash sale on Amazon, customers submit requests for a limited quantity of a product. Each request includes:

[customerId, quantity, bidAmount, timestamp]

Items are allocated using the following rules:

  1. Higher bids get priority.
  2. If multiple customers have the same bid, allocate items in a round-robin manner based on the earliest timestamp until all inventory is allocated.
  3. 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 higher bidding amounts than the 4th request.
The total quantity requested by the first three requests is 19, while the available inventory is 18.

So only one customer ends up with no allocation, which is:

customer ID 4

Function Description

Complete the function:

getUnfulfilledCustomers(requests, totalInventory)

Parameters

  • int requests[n][4]
    A 2D array where each row is: [customerId, quantity, bidAmount, timestamp]
  • int totalInventory
    Total number of items available for allocation

Returns

int[]

A list of customer IDs who did not receive any items, sorted in ascending order.


Constraints

1 ≤ n ≤ 10^4
1 ≤ customerId, quantity, bidAmount, timestamp, totalInventory ≤ 10^8

Sample Case 0

Input

3
4
1 2 5 0
2 1 4 2
3 5 4 6
3

Output

3

Explanation

  • Inventory = 3 items
  • Customer 1 gets 2 items (highest bid = 5) → remaining = 1
  • Customer 2 gets 1 item → remaining = 0
  • Customer 3 gets 0 items

Sample Case 1

Input

4
4
101 3 10 15
102 2 8 20
103 5 8 25
104 4 5 30
8

Output

104

Explanation

  • Inventory = 8 items
  • Customer 101 (highest bid = 10) gets 3 → remaining = 5
  • Customers 102 & 103 (same bid = 8) → round-robin allocation
    • 102 gets 2
    • 103 gets 3
  • Inventory = 0
  • Customer 104 gets nothing

我们长期稳定承接各大科技公司如Capital One、TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

Your email address will not be published. Required fields are marked *