MinHealthGame
https://leetcode.com/discuss/interview-question/1789737/amazon-OA

public class MinHealth {
public static void main(String[] args){
MinHealth minHealth = new MinHealth();
System.out.println(minHealth.findMinHealth(new int[]{1,1,1,1,1},5));
}
public int findMinHealth(int[] power, int armor){
int maxPower = Integer.MIN_VALUE;
int totalSum = 0;
for(int p : power){
totalSum+=p;
maxPower = Math.max(maxPower,p);
}
return totalSum-Math.min(armor,maxPower)+1;
}
}Last updated