Round 1
Questions:
-
Amazon Prime Games is designing a game. The player needs to pass n rounds sequentially in this game. Rules of the play are as follows: a. The player loses power[i] health to complete round i. b. The player's health must be greater than 0 at all times. c. 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 Output: 12
def minimum_starting_health(power, armor): # Calculate the total damage without armor total_damage = sum(power) # Evaluate the minimum damage by using armor on each round min_damage = float('inf') for i in range(len(power)): damage_with_armor = total_damage - min(armor, power[i]) min_damage = min(min_damage, damage_with_armor) # The minimum starting health is the total damage minus the maximum armor usage return min_damage + 1 # Example usage: power = [1, 2, 6, 7] armor = 5 print(minimum_starting_health(power, armor)) # Output should be 12
-
A team of financial analysts at Amazon has designed a stock indicator to determine the consistency of Amazon's stock in delivery returns daily. More formally, the percentage return (rounded off to nearest integer) delivered by the stock each day over the last n days is considered. This is given as an array of integers, stockPrices. The stock's k-consistency score is calculated using the following operations:
- In a single operation, omit a particular day's return from stockPrices array to have one less element, then rejoin the parts of the array. This can be done at most k times.
- The maximum number of contiguous days during which the daily return was the same is defined as the k-consistency score for Amazon's stock. Note that the return may be positive or negative.
As part of the team, you have been assigned to determine the k-consistency score for the stock. You are given an array stockPrices of size n representing the daily percentage return delivered by Amazon stock and a parameter k.
Determine the k-consistency score.
Example:
stockPrices = [1, 1, 2, 1, 2, 1] k = 3
After omitting the integers at 3rd and 5th positions, the array is [1, 1, 1, 1]. It is better not to do the remaining allowable operation. The longest set of contiguous period with the same percentage return is [1, 1, 1, 1]. The k-consistency score is its length, return 4.
Code: The idea is to use sliding Window or dp.
Candidate's Approach
No approach provided.
Interviewer's Feedback
No feedback provided.