Code Question 1
Amazon Prime Games is designing a game. The player needs to pass n rounds sequentially in this game. Rules of play are as follows:
- The player loses power[i] health to complete round i.
- The player's health must be greater than 0 at all times.
- The player can choose to use armor in any one round. The armor will prevent damage of min(armor, power[i]).
Determine the minimum starting health for a player to win the game.
Example
power = [1, 2, 6, 7]
armor = 5
Give the player 12 units of health at the beginning of the game. One of the optimal strategies is to use the armor in the third round and only lose 1 unit instead of 6. The health of the player after each round is:
Round, health
- 12
- 12 - power[0] = 12 - 1 = 11
- 11 - power[1] = 11 - 2 = 9
- 9 - power[2] + armor = 9 - 6 + 5 = 8
- 8 - power[3] = 8 - 7 = 1
No lower starting health will allow a win.
Function Description
Complete the function getMinimumValue in the editor below.
getMinimumValue has the following parameters:
int power[n]: the health cost of each round
int armor: the maximum amount of health that may be returned one round only
Returns
int: the minimum amount of health required at the beginning of the game
Code Question 2
A manager at Amazon is managing a team of n employees with IDs numbered from 0 to n - 1. Some employees are marketing experts and others are developers. The employee with ID i has a skill level of skill[i]. The employee is a marketing expert if expertise[i] is 0 and a developer if expertise[i] is 1.
The manager wants to select a team to work on a project with some contiguous set of IDs [i, i + 1, i + 2, ..., j] such that there is an equal number of marketing experts and developers and the total sum of skills is maximized.
Given two arrays, skill and expertise, find the maximum possible sum of skills of any team that can be formed respecting the above conditions.
Note:
- It is always possible to form a team consisting of zero employees with a total skill of zero.
- A contiguous set of elements is a sequence where each element is adjacent to the next, with no gaps between them. Each element in the set is directly next to the previous one.
Example
Input:
n = 4
expertise = [0, 0, 0, 1]
skill = [10, 2, 3, 4]
The optimal selection is [3, 4] with 1 marketing expert and 1 developer. The sum of skills is 3 + 4 = 7. Hence the answer is 7.
Function Description
Complete the function getMaxSkillSum in the editor below.
getMaxSkillSum takes the following arguments:
- int expertise[n]: the expertise of the employees
- int skill[n]: the skill level of the employees
Returns
long: the maximum possible sum of skill levels of the team
需求,请随时联系我们。
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.