[Uber] OA 2025 Start – 05 Feb (Generic)

Given an array of integers numbers, construct a new array in the following manner:

  • The first element of the new array is the first element of numbers
  • The second element of the new array is the last element of numbers
  • The third element of the new array is the second element of numbers
  • The fourth element of the new array is the second-to-last element of numbers
  • ... and so on, until the new array contains all elements of numbers

Note: You are not expected to provide the most optimal solution, but a solution with time complexity not worse than O(numbers.length^2) will fit within the execution time limit.

Example

  • For numbers = [0, 4, 3, 2, 1], the output should be
    solution(numbers) = [0, 1, 4, 2, 3] Explanation:
    Following the rules above, we get the following sequence
    numbers[0], numbers[4], numbers[1], numbers[3], numbers[2],
    which results in [0, 1, 4, 2, 3].
  • For numbers = [-5, 4, 0, 3, 2, 2], the output should be
    solution(numbers) = [-5, 2, 4, 2, 0, 3] Explanation:
    Following the rules above, we get the following sequence
    numbers[0], numbers[5], numbers[1], numbers[4], numbers[2], numbers[3],
    which results in [-5, 2, 4, 2, 0, 3].

In Unix, there are two common ways to execute a command:

  • Entering its name, e.g., "cp" or "ls"
  • Entering "<index>". This notation is used to repeat the index-th (1-based) command since the start of the session.

For example, suppose that the user has entered the following commands:

ls  
cp  
mv  
11  
13  
16  
  • "11" would trigger the execution of "ls"
  • "13" would repeat "mv"
  • "16" would repeat "mv"

Problem Statement

You are given a sequence of commands commands that the user has entered in the terminal since the start of the session. Each command can be one of the following: "cp", "ls", "mv", or "<index>".

Calculate the number of times each of "cp", "ls", and "mv" commands was executed and return an array of three integers in the following form:

[# of times for "cp", # of times for "ls", # of times for "mv"]

Note: You are not expected to provide the most optimal solution, but a solution with time complexity not worse than O(commands.length^2) will fit within the execution time limit.


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