Maximize the Score from Repeated Row Splits

Quick Overview

Maximize the Score from Repeated Row Splits. The positive values in stoneValue are arranged in a row. At each step, split the current row into two nonempty contiguous rows. Discard the row with the greater sum and add the retained row’s sum to the score.

Maximize the Score from Repeated Row Splits

Company: Infosys

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

### Problem The positive values in `stoneValue` are arranged in a row. At each step, split the current row into two nonempty contiguous rows. Discard the row with the greater sum and add the retained row’s sum to the score. On equal sums, choose which row to retain. Continue until a single stone remains and return the largest total score. ```cpp class Solution { public: int stoneGameV(vector<int>& stoneValue); }; ``` ### Examples **Example 1:** ```text stoneValue = [2,3,4] Output: 4 Explanation: Split [2,3] | [4] to retain [4] and score 4. The other first split can score only 2. ``` **Example 2:** ```text stoneValue = [3,3,3,3] Output: 9 Explanation: Keep one half of sum 6, then one stone of value 3, scoring 6 + 3. ``` ### Constraints - `1 <= stoneValue.length <= 500`. - `1 <= stoneValue[i] <= 10^6`. ### Clarifying Questions Scores start at zero. The initial row cannot be rearranged, and equal-sum choices must consider both possible continuations. ```hint Inspect the structure What choices remain when the two row sums are equal, and how do later scores affect the best choice? ``` ### Reasoning checkpoints - Include exactly the score contributions allowed by each retained-row choice. - Prove global optimality, including equal-sum choices and a singleton row. ### Optional extensions Which repeated interval-sum computations can prefix sums remove?

Overview: Maximize the Score from Repeated Row Splits. The positive values in stoneValue are arranged in a row. At each step, split the current row into two nonempty contiguous rows. Discard the row with the greater sum and add the retained row’s sum to the score.

Infosys logo
Infosys
Source window: 0–3 months · as of Oct 21, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0

Problem

The positive values in stoneValue are arranged in a row. At each step, split the current row into two nonempty contiguous rows. Discard the row with the greater sum and add the retained row’s sum to the score. On equal sums, choose which row to retain. Continue until a single stone remains and return the largest total score.

class Solution {
public:
    int stoneGameV(vector<int>& stoneValue);
};

Examples

Example 1:

stoneValue = [2,3,4]
Output: 4
Explanation: Split [2,3] | [4] to retain [4] and score 4. The other first split can score only 2.

Example 2:

stoneValue = [3,3,3,3]
Output: 9
Explanation: Keep one half of sum 6, then one stone of value 3, scoring 6 + 3.

Constraints

  • 1 <= stoneValue.length <= 500 .
  • 1 <= stoneValue[i] <= 10^6 .

Clarifying Questions Guidance

Scores start at zero. The initial row cannot be rearranged, and equal-sum choices must consider both possible continuations.

Reasoning checkpoints

  • Include exactly the score contributions allowed by each retained-row choice.
  • Prove global optimality, including equal-sum choices and a singleton row.

Optional extensions

Which repeated interval-sum computations can prefix sums remove?