Skip to main content
Back to problems
#3038
Easy Algorithms

Maximum number of operations with the same score i

Array Simulation
52.7% acceptance
Feb 25, 2026
95
28
You are given an array of integers nums. Consider the following operation: Delete the first two elements nums and define the score of the operation as the sum of these two elements. You can perform this operation until nums contains fewer than two elements. Additionally, the same score must be achieved in all operations. Return the maximum number of operations you can perform.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn max_operations(nums: Vec<i32>) -> i32 {
    let target = nums[0] + nums[1];
    nums.chunks(2).take_while(|c| c.len() == 2 && c[0] + c[1] == target).count() as i32
  }
}