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 = 4 
left = "011" and right = "101", score = 1 + 2 = 3 
left = "0111" and right = "01", score = 1 + 1 = 2 
left = "01110" and right = "1", score = 2 + 1 = 3

Example 2:
Input: s = "00111"
Output: 5
Explanation: When left = "00" and right = "111", we get the maximum score = 2 + 3 = 5

Example 3:
Input: s = "1111"
Output: 3

 
Constraints:

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

Source: leetcode | Difficulty: EASY
Tags: String algorithms

Starter code: class Solution:
    def maxScore(self, s: str) -> int:
        

Solutions:
class Solution:

	def maxScore(self, s: str) -> int:
		maxi = 0
		for i in range(1, len(s)):
			a = s[:i]
			b = s[i:]
			maxi = max(a.count('0') + b.count('1'), maxi)
		return maxi


class Solution:

	def maxScore(self, s: str) -> int:
		maxi = 0
		for i in range(len(s) - 1):
			s1 = s[:i + 1]
			i1 = list(s1).count('0')
			s2 = s[i + 1:]
			i2 = list(s2).count('1')
			total = i1 + i2
			if total >= maxi:
				maxi = total
		return maxi


class Solution:

	def maxScore(self, s: str) -> int:
		res = 0
		for i in range(1, len(s)):
			left_count = list(s[:i]).count('0')
			right_count = list(s[i:]).count('1')
			if left_count + right_count > res:
				res = left_count + right_count
		return res


class Solution:

	def maxScore(self, s: str) -> int:
		l = 0
		r = 0
		ans = 0
		for i in range(len(s) - 1):
			if s[i] == '0':
				l += 1
			r = 0
			for j in range(i + 1, len(s)):
				if s[j] == '1':
					r += 1
			ans = max(ans, l + r)
		return ans


class Solution:

	def maxScore(self, s: str) -> int:
		count_0 = 0
		count_1 = 0
		result = []
		for i in range(0, len(s) - 1):
			if s[i] == '0':
				count_0 += 1
			for j in range(i + 1, len(s)):
				if s[j] == '1':
					count_1 += 1
			result += [count_0 + count_1]
			count_1 = 0
		return max(result)


class Solution:

	def maxScore(self, s: str) -> int:
		result = 0
		for i in range(1, len(s)):
			left = s[:i]
			right = s[i:]
			score = 0
			for char in left:
				if char == '0':
					score += 1
			for char in right:
				if char == '1':
					score += 1
			if score > result:
				result = score
		return result


class Solution:

	def maxScore(self, s: str) -> int:
		if len(s) <= 1:
			return getScore(s)
		best = -1
		for i in range(1, len(s)):
			best = max(best, self.getScore(s[:i], s[i:]))
		return best

	def getScore(self, left, right):
		return left.count('0') + right.count('1')


class Solution:

	def maxScore(self, s: str) -> int:
		lis = []
		for i in range(1, len(s)):
			num1 = 0
			num2 = 0
			s1 = s[:i]
			s2 = s[i:]
			for i in s1:
				if i == '0':
					num1 += 1
			for i in s2:
				if i == '1':
					num2 += 1
			lis.append(num1 + num2)
		lis.sort(reverse=True)
		return lis[0]


class Solution:

	def maxScore(self, s: str) -> int:

		def countchar(given, char):
			count = 0
			for x in given:
				if x == char:
					count += 1
			return count
		maxans = 0
		for i in range(len(s) - 1):
			ans = 0
			if s[:i + 1]:
				leftcount = countchar(s[:i + 1], '0')
				ans += leftcount
			if s[i + 1:]:
				rightcount = countchar(s[i + 1:], '1')
				ans += rightcount
			maxans = max(maxans, ans)
		return maxans


class Solution:

	def maxScore(self, s: str) -> int:
		list_score = []
		for i in range(1, len(s)):
			score = 0
			for j in s[:i]:
				if j == '0':
					score += 1
			for j in s[i:]:
				if j == '1':
					score += 1
			list_score.append(score)
		return max(list_score)


class Solution:

	def maxScore(self, s: str) -> int:
		n = len(s)
		result = 0
		if n <= 1:
			return n
		for i in range(1, n):
			left = s[:i]
			right = s[i:n]
			leftZeroCount = 0
			rightOneCount = 0
			for j in range(len(left)):
				if left[j] == '0':
					leftZeroCount += 1
			for k in range(len(right)):
				if right[k] == '1':
					rightOneCount += 1
			if leftZeroCount + rightOneCount > result:
				result = leftZeroCount + rightOneCount
		return result


class Solution:

	def maxScore(self, s: str) -> int:
		n = len(s)
		zeros = [0 for ii in range(n)]
		ones = [0 for ii in range(n)]
		if s[0] == '0':
			zeros[0] = 1
		else:
			zeros[0] = 0
		if s[n - 1] == '1':
			ones[n - 1] = 1
		else:
			ones[n - 1] = 0
		for ii in range(1, n):
			if s[ii] == '0':
				zeros[ii] = zeros[ii - 1] + 1
			else:
				zeros[ii] = zeros[ii - 1]
			if s[n - 1 - ii] == '1':
				ones[n - 1 - ii] = ones[n - ii] + 1
			else:
				ones[n - 1 - ii] = ones[n - ii]
		if s[0] == '1':
			ones[0] -= 1
		if s[n - 1] == '0':
			zeros[n - 1] -= 1
		mx = 0
		for ii in range(len(zeros)):
			if zeros[ii] + ones[ii] > mx:
				mx = zeros[ii] + ones[ii]
		return mx


class Solution:

	def maxScore(self, s: str) -> int:
		res = 0
		for i in range(len(s)):
			if i != len(s) - 1:
				t = self.calcScore(s[:i + 1], s[i + 1:])
				res = max(res, t)
		return res

	def calcScore(self, s1: str, s2: str) -> int:
		return s1.count('0') + s2.count('1')