You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# 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.
class Solution:
def maxScore(self, s: str) -> int:
# Find the total number of 1's in the string, using map function we can convert each digit into int from str
pref_sum = sum(list(map(int, list(s))))
# Note down the max score
max_score = 0
for i in range (1, len(s)):
# find the number of ones in the right substring
right_score = sum(list(map(int, list(s[i: ]))))
# find the number of ones in the left string, which is then subtracted from the len of the left substring to give the number of zeros in the left