← Back to challenges

Maximum Score From Two Parts of a String

JavaScriptHardalgorithmsconditionsloopsstrings

Instructions

Given a string s formed from zeros and ones, return the maximum score after splitting the string into two non-empty substrings (left and right).

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

Examples

maxScore("00111") ➞ 5

maxScore("1111") ➞ 3

maxScore("01001") ➞ 4

maxScore("010101010101010101") ➞ 10

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.