Maximum Score After Splitting a String

Given a string s of zeros and ones, return the maximum score after splitting the string into two non-empty substrings, a left substring and a right substring.

The score after splitting a string is the number of zeros in the left substring plus the number of ones in the right substring.

Example 1
Inputs = "011101"
Output5
All possible non-empty splits have scores 5, 4, 3, 2, and 3, so the maximum score is 5.
Example 2
Inputs = "00111"
Output5
When left = "00" and right = "111", the score is 2 + 3 = 5, which is maximum.

Constraints

  • 2 <= s.length <= 500
  • The string s consists of characters '0' and '1' only.

Asked at 3 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