Amazon OA 2026 最新真题整理|两道高频 Coding 题完整题面 – OA代做 – 一亩三分地

Code Question 1

Amazon is hosting a flash sale for a high-demand product, sourced from multiple suppliers. Each supplier has a limited stock, represented by the array supplierStock, where each element indicates the number of units available from a particular supplier.

To maximize revenue, Amazon follows a dynamic pricing strategy with the following rules:

  • At any given time, only one unit can be sold from a supplier.
  • The revenue from selling a unit is equal to the supplier’s current stock level at that moment.
  • After a sale, the supplier’s stock decreases by one, and the revenue for selling another unit from that supplier is adjusted accordingly.
  • If a supplier’s stock reaches zero, no further sales can be made from them.

Amazon aims to sell units in a way that maximizes total revenue by optimally selecting the available suppliers.

Given an array supplierStock of length n, representing stock levels across suppliers, and an integer orders, representing the total number of items Amazon needs to sell, determine the maximum revenue that can be generated.


Example

supplierStock = [3, 5]
orders = 6

In this case, the optimal selling strategy is as follows:

  1. Sell 1 unit from the supplier 1 with 5 stock, generating a revenue of 5.
  2. Sell 1 unit from the same supplier 1 generating a revenue of 4.
  3. Sell 1 unit at 3 from supplier 2, generating a revenue of 3.
  4. Sell 1 unit at 3 from supplier 1, generating a revenue of 3.
  5. Sell 1 unit at 3 from supplier 2, generating a revenue of 2.
  6. Sell 1 unit at 3 from supplier 1, generating a revenue of 2.

The remaining stock levels for the suppliers is [1, 1] after fulfilling orders = 6, and the maximum revenue generated is:

5 + 4 + (2 * 3) + (2 * 2) = 19

It is guaranteed that no other selling strategy can yield higher total revenue than 19.


Code Question 2

In Amazon’s Smart Cities Management System, each city has a given population and some cities are equipped with security units.

You are given:

  • An integer array population of size n, where population[i] is the number of inhabitants in the i-th city.
  • A binary string unit of length n, where unit[i] = '1' means city i has a security unit, and '0' means it does not.

Relocation Rule:

  • A security unit at city i (where i > 1) can be moved one step to the left to city i - 1.
  • Each unit can be moved at most once.
  • If moved, city i loses its unit and city i - 1 gains one.
  • City 1 security unit cannot be moved further left.

A city is protected if it has a security unit after all relocations.

Determine the maximum population that can be protected by optimally relocating the security units.


Note

The problem uses 1-based indexing, meaning city indices, the population array, and the unit binary string all start from 1 and go up to n, with each city having a corresponding entry in both the array and the string.


Example

n = 5
population = [10, 5, 8, 9, 6]
unit = "01101"
Relocated Index (i to i-1)Previous ConfigurationNew ConfigurationSafe Inhabitants
2011011010110 + 8 + 6 = 24
5101011011010 + 8 + 9 = 27

Thus, 27 is the maximum number of inhabitants that can be protected. No other relocation strategy can yield a higher safe population than 27. Hence answer is 27.

我们长期稳定承接各大科技公司如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 *