3038. Maximum Number of Operations With the Same Score I Easy

@problem@discussion
#Array#Simulation



1/**
2 * [3038] Maximum Number of Operations With the Same Score I
3 *
4 * You are given an array of integers nums. Consider the following operation:
5 * 
6 * 	Delete the first two elements nums and define the score of the operation as the sum of these two elements.
7 * 
8 * You can perform this operation until nums contains fewer than two elements. Additionally, the same score must be achieved in all operations.
9 * Return the maximum number of operations you can perform.
10 *  
11 * <strong class="example">Example 1:
12 * <div class="example-block">
13 * Input: <span class="example-io">nums = [3,2,1,4,5]</span>
14 * Output: <span class="example-io">2</span>
15 * Explanation:
16 * 
17 * 	We can perform the first operation with the score 3 + 2 = 5. After this operation, nums = [1,4,5].
18 * 	We can perform the second operation as its score is 4 + 1 = 5, the same as the previous operation. After this operation, nums = [5].
19 * 	As there are fewer than two elements, we can't perform more operations.
20 * </div>
21 * <strong class="example">Example 2:
22 * <div class="example-block">
23 * Input: <span class="example-io">nums = [1,5,3,3,4,1,3,2,2,3]</span>
24 * Output: <span class="example-io">2</span>
25 * Explanation:
26 * 
27 * 	We can perform the first operation with the score 1 + 5 = 6. After this operation, nums = [3,3,4,1,3,2,2,3].
28 * 	We can perform the second operation as its score is 3 + 3 = 6, the same as the previous operation. After this operation, nums = [4,1,3,2,2,3].
29 * 	We cannot perform the next operation as its score is 4 + 1 = 5, which is different from the previous scores.
30 * </div>
31 * <strong class="example">Example 3:
32 * <div class="example-block">
33 * Input: <span class="example-io">nums = [5,3]</span>
34 * Output: <span class="example-io">1</span>
35 * </div>
36 *  
37 * Constraints:
38 * 
39 * 	2 <= nums.length <= 100
40 * 	1 <= nums[i] <= 1000
41 * 
42 */
43pub struct Solution {}
44
45// problem: https://leetcode.com/problems/maximum-number-of-operations-with-the-same-score-i/
46// discuss: https://leetcode.com/problems/maximum-number-of-operations-with-the-same-score-i/discuss/?currentPage=1&orderBy=most_votes&query=
47
48// submission codes start here
49
50impl Solution {
51    pub fn max_operations(nums: Vec<i32>) -> i32 {
52        0
53    }
54}
55
56// submission codes end
57
58#[cfg(test)]
59mod tests {
60    use super::*;
61
62    #[test]
63    fn test_3038() {
64    }
65}
66


Back
© 2025 bowen.ge All Rights Reserved.