Code Question 1
Amazon Academy has launched a new course on Quantum Physics.
The course has n
chapters, each chapter has memory[i]
memory points, which a student gains or loses while reading that chapter. The course has a requirement: in order to study the i-th
chapter, the student must revisit all the previous chapters.
A student gains memory[0] + memory[1] + ... + memory[i]
memory points for reading the i-th
chapter. The total memory points is the sum of memory points gained while reading each chapter.
Students can read the chapters in any order and want to maximize their total memory points. Find the maximum total memory points a student can score ensuring that all the chapters are read.
Function Description
Complete the function maximizeTotalMemoryPoints
in the editor below.
maximizeTotalMemoryPoints
This function has the following parameter:int memory[n]
: the memory points associated with each chapter.
- Returns
long_int
: The maximum possible total memory points.
Constraints
1 ≤ n ≤ 10^5
-10^3 ≤ memory[i] ≤ 10^3
Example
Given memory = [3, 4, 5]
.
Considering all permutations of reading the chapters and their total memory points:
[3, 4, 5]
→ Corresponding memory points:[3, 7, 12]
→ Total = 3 + 7 + 12 = 21[3, 5, 4]
→ Corresponding memory points:[3, 8, 12]
→ Total = 3 + 8 + 12 = 23[4, 3, 5]
→ Corresponding memory points:[4, 7, 12]
→ Total = 4 + 7 + 12 = 23[4, 5, 3]
→ Corresponding memory points:[4, 9, 12]
→ Total = 4 + 9 + 12 = 25[5, 3, 4]
→ Corresponding memory points:[5, 8, 12]
→ Total = 5 + 8 + 12 = 25[5, 4, 3]
→ Corresponding memory points:[5, 9, 12]
→ Total = 5 + 9 + 12 = 26
The maximum number of total memory points is 26.
Code Question 2
A team of financial analysts at Amazon closely monitors revenue generated by a newly launched product. They classify a period of one or more consecutive days as a stable-growth period if the revenue generated by the product takes no more than k distinct values over that period.
Given an array revenues
of size n, that represents the revenues generated by the new product on n consecutive days, and an integer k, determine the total number of stable-growth periods over the n days. Since the answer can be large, return it modulo (10^9 + 7).
Example
Suppose n = 3, k = 1, and revenues = [1, 2, 1]
.
Indices of days | Periods | Distinct Values |
---|---|---|
[0] | [1] | 1 |
[0, 1] | [1, 2] | 2 |
[0, 1, 2] | [1, 2, 1] | 2 |
[1] | [2] | 1 |
[1, 2] | [2, 1] | 2 |
[2] | [1] | 1 |
There are three periods with k = 1 or fewer distinct values. The number of stable growth periods is 3.
Function Description
Complete the getStablePeriodsCount
function in the editor below.
Parameters
int revenues[n]
: the revenues generated by the new product over n daysint k
: the maximum number of distinct values in a stable growth period
Returns
int
: the number of stable growth periods of the product over n days, modulo (10^9 + 7)
Constraints
- 1 ≤ n ≤ 10^5
- 1 ≤ k ≤ n
- -10^9 ≤
revenues[i]
≤ 10^9
我们长期稳定承接各大科技公司如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.