THE CHALLENGESPLIT_SCORE — Cut in the best place.
You are given a binary string s (only 0s and 1s). Cut it into two non-empty parts: left = s[0:i], right = s[i:]. The score is the number of 0s on the left plus the number of 1s on the right. Print the highest possible score.
Input:
- a single line: the string of 0s and 1s
Output:
the highest score.
Example:
011101
gives
5
How to break it down:
1. score(s, i): returns the score for a cut at index i.
2. Try every cut from 1 to len(s) - 1 and keep the highest.
Challenge: score(s, i) = zeros on the left + ones on the right with count() and slices - a single loop.
Checks (verified automatically before your code runs):
- At least 1 function definition.
- At least 1 call to score().
- At least 1 slice like s[a:b].
- At most 1 loop in the whole program (for, while and comprehensions all count).