Maximum Number of Operations With the Same Score I

You are given an array of integers nums. Consider the following operation:

  • Delete the first two elements of 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.

Example 1
Inputnums = [3,2,1,4,5]
Output2
The first two operations both have score 5, and then fewer than two elements remain.
Example 2
Inputnums = [1,5,3,3,4,1,3,2,2,3]
Output2
The first two operations both have score 6, but the next operation would have score 5, so it cannot be performed.

Constraints

  • 2 <= nums.length <= 100
  • 1 <= nums[i] <= 1000

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate