Optiver OA 真题202509 – 一亩三分地 – OA 代写 – OA writing

🐿️ Squirrel Nut Hiding & Retrieving Problem

You are to implement a class SquirrelResearch to simulate the behavior of squirrels hiding and retrieving nuts across different locations. Each location contains multiple storage levels, shaped like a cone, with increasing capacities at higher levels. Nut hiding and retrieval are subject to specific constraints and rules.


📌 Guaranteed Constraints

  • If any constraint is violated when performing an operation, the operation must fail.
  • If a constraint is said to be "guaranteed", you may assume it is never violated.
  • Action functions include a timestamp indicating when such action has taken place. They are guaranteed to be globally ever increasing.
  • Timestamps are represented as number of seconds since the Unix Epoch (Jan 1, 1970 UTC), using floating-point values valid to the millisecond precision. They are guaranteed to be positive numbers and fit into 32 bits.
  • Weights are represented in grams, using floating-point values valid to the milligram precision.
  • Guaranteed input constraints:
    • 0 < N < 2¹⁵, where N is the total number of instructions given to the program.

🧱 Constructor

__init__(self, locations: dict[string, integer])

Description:

  • Initializes the class with all available hiding locations. This represents the constructor of the class in whatever programming language being used.
  • locations is a map where the key is the location's unique identifier, and the value is the location's number of levels.
  • Hiding locations are shaped like a cone, forming storage levels that grow in size according to the Fibonacci sequence starting from the 3rd digit.
    • For example, a location with 3 levels can fit up to 6 nuts: 1 at the deepest level, 2 at the middle level, and 3 at the top level.
  • If the number of levels is 1, capacity is [1].

Input Constraints:

  • 1 ≤ levels < 2⁵
  • 0 ≤ Q < 2²⁰, where Q is the length of locations.

🥜 HideNut Operation

HideNut(timestamp: float, location_id: string, nut_id: string, nut_weight: float, time_to_expire: float) -> bool

Description:

  • A squirrel attempts to hide a nut in a location. Returns true if the operation succeeds, and false otherwise.
  • Locations are filled from the deepest level upwards. Only once a level is completely filled, nuts start filling the next level.
  • nut_id is a unique string identifier for a nut. If a nut is already hidden (anywhere), the operation fails.
  • If the location is full or invalid, the operation fails.
  • time_to_expire represents the time it takes for this nut to expire, starting at timestamp. In other words, a nut is considered expired immediately after timestamp + time_to_expire. It's represented in seconds using floating-point values valid to the millisecond precision.

Input Constraints:

  • 0 < nut_weight < 20

🐿️ RetrieveNuts Operation

RetrieveNuts(timestamp: float, location_id: string, max_squirrel_capacity_in_nuts: integer) -> list[string]

Description:

  • A squirrel attempts to retrieve nuts from a location. Returns a list with the nut_ids retrieved (in order of retrieval) if the operation succeeds, and an empty list otherwise.
  • max_squirrel_capacity_in_nuts indicates the maximum number of nuts the current squirrel can retrieve.
  • Nuts are retrieved first by level, starting from the upmost level with nuts.
  • Per level, heavier nuts are retrieved first.
  • If the upmost level is occupied by less than 50% of its total capacity, the next level becomes reachable, and the squirrel will prefer nuts from there if they’re heavier.
  • If there’s a tie on weight, the nut with the smallest id (alphabetically) is retrieved first.
  • Every time a nut is taken out of a level that's not the upmost level with nuts, the lightest nut from the level above falls into its place.
  • If an expired nut is retrieved, it gets immediately discarded by the squirrel.
  • Retrieved and discarded nuts are removed from the location.
  • Once retrieved, a nut_id may be used again to identify other nuts.
  • If the location is empty or invalid, the operation fails.

Input Constraints:

  • 0 ≤ max_squirrel_capacity_in_nuts < 2¹⁰

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