Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Operations With the Same Score II

Maximum Number of Operations With the Same Score II asks you to remove the first two, last two, or one from each end of an array, ensuring every pair has the same sum. Return the maximum operations.

Statement

Given an array of integers nums, you can perform any of the following actions in a single operation if nums contains at least 22 elements:

  • Delete the first two elements of nums, with a score equal to their sum.

  • Delete the last two elements of nums, with a score equal to their sum.

  • Delete the first element and the last element of nums, with a score equal to their sum.

The score of each operation must be identical for all performed operations.

Return the maximum number of operations that can be performed such that all operations have the same score.

Constraints:

  • 2≤2 \leq nums.length ≤2000\leq 2000

  • 1≤1 \leq nums[i] ≤1000\leq 1000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Operations With the Same Score II

Maximum Number of Operations With the Same Score II asks you to remove the first two, last two, or one from each end of an array, ensuring every pair has the same sum. Return the maximum operations.

Statement

Given an array of integers nums, you can perform any of the following actions in a single operation if nums contains at least 22 elements:

  • Delete the first two elements of nums, with a score equal to their sum.

  • Delete the last two elements of nums, with a score equal to their sum.

  • Delete the first element and the last element of nums, with a score equal to their sum.

The score of each operation must be identical for all performed operations.

Return the maximum number of operations that can be performed such that all operations have the same score.

Constraints:

  • 2≤2 \leq nums.length ≤2000\leq 2000

  • 1≤1 \leq nums[i] ≤1000\leq 1000