1705. Maximum Number of Eaten Apples Medium
1/**
2 * [1705] Maximum Number of Eaten Apples
3 *
4 * There is a special kind of apple tree that grows apples every day for n days. On the i^th day, the tree grows apples[i] apples that will rot after days[i] days, that is on day i + 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 by apples[i] == 0 and days[i] == 0.
5 * You decided to eat at most one apple a day (to keep the doctors away). Note that you can keep eating after the first n days.
6 * Given two integer arrays days and apples of length n, return the maximum number of apples you can eat.
7 *
8 * Example 1:
9 *
10 * Input: apples = [1,2,3,5,2], days = [3,2,1,4,2]
11 * Output: 7
12 * Explanation: You can eat 7 apples:
13 * - On the first day, you eat an apple that grew on the first day.
14 * - On the second day, you eat an apple that grew on the second day.
15 * - 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.
16 * - On the fourth to the seventh days, you eat apples that grew on the fourth day.
17 *
18 * Example 2:
19 *
20 * Input: apples = [3,0,0,0,0,2], days = [3,0,0,0,0,2]
21 * Output: 5
22 * Explanation: You can eat 5 apples:
23 * - On the first to the third day you eat apples that grew on the first day.
24 * - Do nothing on the fouth and fifth days.
25 * - On the sixth and seventh days you eat apples that grew on the sixth day.
26 *
27 *
28 * Constraints:
29 *
30 * n == apples.length == days.length
31 * 1 <= n <= 2 * 10^4
32 * 0 <= apples[i], days[i] <= 2 * 10^4
33 * days[i] = 0 if and only if apples[i] = 0.
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/maximum-number-of-eaten-apples/
39// discuss: https://leetcode.com/problems/maximum-number-of-eaten-apples/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn eaten_apples(apples: Vec<i32>, days: Vec<i32>) -> i32 {
45 0
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_1705() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.