Task 1
There is a road consisting of N segments (numbered from 0 to N-1) described by an array R of integers. The K-th segment is described by an integer R[K]. If the segment is smooth (there is no pothole in it), then R[K] = 0; otherwise it contains a pothole of depth R[K]. Consecutive potholes join together and create a larger group of potholes.
The pothole indicator is the number of consecutive single potholes that have joined into a pothole group, multiplied by the depth of the deepest pothole among them. For example, the indicator for a group of three consecutive joined potholes of sizes [1, 4, 1] is 3 * 4 = 12.
What is the largest pothole indicator on the entire road?
Write a function:
def solution(R)
that, given an array R of N integers, returns the largest pothole indicator on the road.
Examples
- Given R = [0, 2, 1, 1, 0, 4, 1], the function should return 8.
The potholes in the fragment [2, 1, 1] join into one pothole group. It is made of three segments and the deepest pothole among them is of depth 2, so its pothole indicator is equal to 3 * 2 = 6.
The potholes in the fragment [4, 1] join into another pothole group. It is made of two consecutive potholes and the deepest pothole among them is of depth 4, so its pothole indicator is equal to 2 * 4 = 8. - Given R = [1, 4, 1, 0, 5, 2, 3, 0, 8], the function should return 15.
The consecutive potholes that join into three larger pothole groups are as follows:- [1, 4, 1] with indicator 3 * 4 = 12;
- [5, 2, 3] with indicator 3 * 5 = 15;
- [8] with indicator 1 * 8 = 8.
- Given R = [9, 8, 7, 0, 0, 0, 2, 3, 6, 4], the function should return 27.
The consecutive potholes that join into two larger pothole groups are as follows:- [9, 8, 7] with indicator 3 * 9 = 27;
- [2, 3, 6, 4] with indicator 4 * 6 = 24.
- Given R = [0, 0, 0], the function should return 0.
There are no potholes on the road, so the highest pothole indicator is equal to 0.

Task 2
You are given a record of the historical prices of an investment asset from the last N days. Analyze the record in order to calculate what could have been your maximum income. Assume you started with one asset of this type and could hold at most one at a time. You could choose to sell the asset whenever you held one. If you did not hold an asset at some moment, you could always afford to buy an asset (assume you had infinite money available).
What is the maximum income you could make?
Write a function:
def solution(A)
that, given an array A of length N representing a record of prices over the last N days, returns the maximum income you could make. As the result may be large, return its last nine digits without leading zeros (return the result modulo 1,000,000,000).
Examples
- Given A = [4, 1, 2, 3], the function should return 6.
You could sell the product on the first day (for 4), buy it on the second (for 1) and sell it again on the last day (for 3).
The income would be equal to 4 - 1 + 3 = 6. - Given A = [1, 2, 3, 3, 2, 1, 5], the function should return 7.
You could sell the product when its value was 3, buy it when it changed to 1, and sell it again when it was worth 5. - Given A = [1000000000, 1, 2, 2, 1000000000, 1, 1000000000], the function should return 999999998.

Task 3
There are N cities (numbered from 1 to N, from left to right) arranged in a row and N-1 one-way roads between them:
1 → 2 → 3 → ... → N-1 → N.
The government has a plan to build M new roads. The roads will be built one by one. The K-th road will connect the A[K]-th city with the B[K]-th city (roads are numbered from 0 to M-1). Each road will lead from the left to the right, from a city with a smaller number to a city with a larger number. No two roads will intersect. Formally, there will be no two roads A → B and C → D, such that A < C < B < D.
Jack lives in city number 1 and his school is located in city number N. He wants to know the distance from home to school after each new road is built.
Write a function:
def solution(A, B, N)
that, given two arrays A, B consisting of M integers each and an integer N, returns an array D consisting of M integers, where D[K] denotes the distance from home to school after building the first K roads. The distance is the minimum number of roads required to move between two cities.
Examples
- Given A = [2, 5, 1], B = [4, 7, 4] and N = 7, the function should return [5, 4, 3].
- After building the first road (2 → 4), the shortest path from home to school is:
1 → 2 → 4 → 5 → 6 → 7, and its length is 5. - After building the second road (5 → 7), the shortest path from home to school is:
1 → 2 → 4 → 5 → 7, and its length is 4. - After building the third road (1 → 4), the shortest path from home to school is:
1 → 4 → 5 → 7, and its length is 3.
- After building the first road (2 → 4), the shortest path from home to school is:
- Given A = [1, 1, 1], B = [7, 4, 6] and N = 7, the function should return [1, 1, 1].
After building the first road (1 → 7), the length of the shortest path from home to school is 1. The roads built subsequently do not improve the result. - Given A = [30, 50, 40], B = [40, 60, 50] and N = 100, the function should return [90, 81, 72].
Each new road shortens the distance from home to school by 9.

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

