CS-OA cs-vo Faang

Amazon NG OA – Amazon 笔试真题 – Max Median Sum – Max Negative PnL

近期Amazon 的NG岗位火热开放中,还是常见的70分钟2道题,平台hackrank.

Code 1: Max Median Sum

Given an array of integers (unsorted) and a value n indicating the number of channels, you have to send all these numbers through n channels (At least one number should go through each channel).

Example:

Input:
nums = [1, 2, 3, 2, 1, 5], n = 3

  • Send 1, 2, 3 through channel 1; 2 through channel 2; 1, 5 through channel 3.
  • Calculate median of each channel:
    • Channel 1: median of (1, 2, 3) is 2
    • Channel 2: median of (2) is 2
    • Channel 3: median of (1, 5) is 3
  • Sum = 7

Alternative distribution:
Send 1, 2, 2, 1 through channel 1; 3 through channel 2; 5 through channel 3.

  • Calculate median of each channel:
    • Channel 1: median of (1, 2, 2, 1) is 1.5
    • Channel 2: median of (3) is 3
    • Channel 3: median of (5) is 5
  • Sum = 9.5

Code 2: Max Negative PnL

You are analyzing the market trends of Amazon stocks. An AWS financial service model returned an array of integers, PnL (Profit and Loss) for your portfolio representing that in the ith month, you will either gain or lose PnL. All reported PnL values are positive, representing gains. As part of the analysis, you will perform the following operation on the PnL array any number of times: Choose any month i (0 > i < n) and multiply PnL[i] by -1. Find the maximum number of months you can afford to face a loss, have a negative PnL, such that the cumulative PnL for each of the n months remains strictly positive. Note: the cumulative PnL for the ith month is defined as the sum of PnL from the starting month up to the ith month.

Example inputs and answers:

  • PnL = [5, 3, 1, 2]: answer is 2
  • PnL = [1, 1, 1, 1, 1]: answer is 2
  • PnL = [5, 2, 3, 5, 2, 3]: answer is 3

我们提供OA代写服务,代面试服务,面试辅助服务等。对于OA代写我们将确保你获得满分,联系我们立即进行预约。

We provide services for writing online assessments (OA), proxy interviews, and interview assistance. For the OA writing service, we will ensure that you achieve a perfect score. Contact us now to make an appointment.

Leave a Reply

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