Maximum Score After Splitting A String: Optimal Solution In PHP
Precompute prefix sum of ones in string s. Iterate over possible splits, counting zeros in left substring and using prefix sum for right substring. Update max score as the sum of zeros in left part and ones in right part. Return max score found.
1422. Maximum Score After Splitting a String Difficulty: Easy Topics: String, Prefix Sum Given a string s of zeros and ones, return the maximum score after splitting the string into two non-empty substrings (i.e. left substring and 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: Input: s = "011101" Output: 5 Explanation: All possible ways of splitting s into two non-empty substrings are: left = "0" and right = "11101", score = 1 + 4 = 5 left = "01" and right = "1101", score = 1 + 3 =...