Panda Guru LogoPanda
Guru

Amazon OA | SDE 1

Amazon OA

Questions:

Question 1: Minimum Health to Beat Game

You are playing a game that has n levels numbered from 0 to n - 1. You are given a 0-indexed integer array damage where damage[i] is the amount of health you will lose to complete the ith level.

You are also given an integer armor. You may use your armor ability at most once during the game on any level which will protect you from at most armor damage. You must complete the levels in order and your health must be greater than 0 at all times to beat the game.

Return the minimum health you need to start with to beat the game.

Sample Test case:

Input: damage = [2,7,4,3], armor = 4 Output: **13**

Explanation: One optimal way to beat the game starting at 13 health is: On round 1, take 2 damage. You have 13 - 2 = 11 health. On round 2, take 7 damage. You have 11 - 7 = 4 health. On round 3, use your armor to protect you from 4 damage. You have 4 - 0 = 4 health. On round 4, take 3 damage. You have 4 - 3 = 1 health. Note that 13 is the minimum health you need to start with to beat the game.

LeetCode Link

Question 2: Minimum Operations to Make the Integer Zero

You are given an integer array and you need to perform some operations on the array to make all the elements equal to 0. In one operation you can select a prefix of the given array and increment or decrement all the elements of the prefix by 1.

You have an array arr consisting of n integers. Find the minimum number of operations required to convert every element of this array to 0.

Sample Test Case:

cart = [3,2,0,0,-1] Output: **5**

Explanation: ops 1 => [2,2,0,0,-1] -> prefix length = 1
ops 2 => [1,1,0,0,-1] -> prefix length = 1
ops 3 => [0,0,-1,-1,-1] -> prefix length = 4
ops 4 => [-1,-1,-1,-1,-1] -> prefix length = 2
ops 5 => [0,0,0,0,0] -> prefix length = 5

Couldn't find the exact question but here is a similar question.
LeetCode Link

Candidate's Approach
  • For Question 1, the candidate solved it in 2 minutes.
  • For Question 2, it took about 5-10 minutes to figure out the solution, and all test cases passed.
Interviewer's Feedback

No feedback provided.