Class Solution
-
- All Implemented Interfaces:
public final class Solution1705 - Maximum Number of Eaten Apples.
Medium
There is a special kind of apple tree that grows apples every day for
ndays. On the <code>i<sup>th</sup></code> day, the tree growsapples[i]apples that will rot afterdays[i]days, that is on dayi + days[i]the apples will be rotten and cannot be eaten. On some days, the apple tree does not grow any apples, which are denoted byapples[i] == 0anddays[i] == 0.You decided to eat at most one apple a day (to keep the doctors away). Note that you can keep eating after the first
ndays.Given two integer arrays
daysandapplesof lengthn, return the maximum number of apples you can eat.Example 1:
Input: apples = 1,2,3,5,2, days = 3,2,1,4,2
Output: 7
Explanation: You can eat 7 apples:
On the first day, you eat an apple that grew on the first day.
On the second day, you eat an apple that grew on the second day.
On the third day, you eat an apple that grew on the second day. After this day, the apples that grew on the third day rot.
On the fourth to the seventh days, you eat apples that grew on the fourth day.
Example 2:
Input: apples = 3,0,0,0,0,2, days = 3,0,0,0,0,2
Output: 5
Explanation: You can eat 5 apples:
On the first to the third day you eat apples that grew on the first day.
Do nothing on the fouth and fifth days.
On the sixth and seventh days you eat apples that grew on the sixth day.
Constraints:
n == apples.length == days.length<code>1 <= n <= 2 * 10<sup>4</sup></code>
<code>0 <= applesi, daysi<= 2 * 10<sup>4</sup></code>
days[i] = 0if and only ifapples[i] = 0.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegereatenApples(IntArray apples, IntArray days)-
-
Method Detail
-
eatenApples
final Integer eatenApples(IntArray apples, IntArray days)
-
-
-
-