**Code Question 1:**

New Year’s Day is around the corner and Amazon is having a sale. They have a list of items they are considering but they may need to remove some of them. Determine the minimum number of items to remove from an array of prices so that the sum of prices of any k items does not exceed a threshold.

**Note:** If the number of items in the list is less than k, then there is no need to remove any more items.

**Example:**

`prices = [3, 2, 1, 4, 6, 5]`

k = 3

threshold = 14

The sum of prices for every k = 3 items must not be more than threshold = 14. The sum of the prices of the last three items is 6 + 5 + 4 = 15. The item priced $6 can be removed leaving:

`[3, 2, 1, 4, 5]`

No 3 items’ prices sum to greater than 14. Only 1 item needs to be removed.

**Function Description:**

Complete the function `reduceGifts`

in the editor below.

`reduceGifts`

has the following parameters:

`int prices[n]`

: the prices of each item`int k`

: the number of items to sum`int threshold`

: the maximum price of k items

**Returns:**

`int`

: the minimum number of items to remove from the list

**Constraints:**

1 ≤ k ≤ n ≤ 10^5

1 ≤ threshold ≤ 10^9

1 ≤ prices[i] ≤ 10^9

**Sample Input for Custom Testing:**

`STDIN FUNCTION`

8 -> prices[] size n = 8

prices = [9, 6, 3, 2, 9, 10, 11]

3

10 -> k = 2

13 -> threshold = 13

**Sample Output:**

`2`

**Explanation:**

Items with prices 9 and 7 have a sum larger than 13. After removing these two items, prices[] = [6, 2, 7, 2]. No items have a sum of prices greater than the threshold.

**Code Question 2:**

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[i]. 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, i.e., have a negative PnL, such that the cumulative PnL for each of the n months remains strictly positive, i.e., remains greater than 0.

**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:**

Consider, n = 4, and PnL = [5, 3, 1, 2]

Some of the possible arrays after performing the given operation some number of times:

Modified PnL | Cumulative PnL | Number of negatives | Is Valid | Comments |
---|---|---|---|---|

[5, 3, -1, 2] | [5, 2, 1, 3] | 2 | Yes | The operation was performed on the second and third months. All the cumulative PnLs are positive. |

[5, 3, -1, -2] | [5, 2, -1, 3] | 3 | No | The last cumulative PnL is negative, hence invalid. |

[5, 3, 1, -2] | [5, 2, 3, 1] | 2 | Yes | All the cumulative PnLs are positive. |

**Function Description:**

Complete the function `getMaxNegativePnL`

in the editor below.

`getMaxNegativePnL`

has the following parameter:

`int PnL[n]`

: an array of integers

**Returns:**

`int`

: the maximum number of negatives such that the cumulative PnL for every month remains strictly positive

**Constraints:**

1 ≤ n ≤ 10^5

1 ≤ PnL[i] ≤ 10^9

**Sample Input for Custom Testing:**

`STDIN FUNCTION`

4 -> PnL[] size n = 4

PnL = [1, 1, 1, 1, 1]

**Sample Output:**

`2`

**Explanation:**

There are multiple possible PnLs such as [1, -1, -1, 1, 1], [-1, 1, -1, 1, -1], etc. However, it is optimal to modify the PnL to be [1, 1, -1, 1, -1] or [1, 1, 1, -1, -1].

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