1214. Maximum Score After Splitting String

MediumDynamic ProgrammingPartition DP

Given a binary string s, split it into two non-empty parts (left and right). The score is the number of zeros in the left part plus the number of ones in the right part. Return the maximum score over all splits. The input is JSON {s}.

Input: JSON {s}.

Output: Integer — the maximum score.

Examples

Example 1
Input: {"s":"011101"}
Output: 5
Explanation: An optimal split scores 5.
Example 2
Input: {"s":"00"}
Output: 1
Explanation: One zero on the left.
Example 3
Input: {"s":"1111"}
Output: 3
Explanation: Three ones on the right.

Constraints

Asked by

GoogleMetaAmazon
Solve this problem in the editor →