# LeetCode – Strings – Maximum Score After Splitting a String

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```
``class Solution {    public int maxScore(String s) {        int max = 0;        for(int i=0;i<s.length()-1;i++){            String left = s.substring(0,i+1);            String right = s.substring(i+1,s.length());            left = left.replaceAll("1","");            right = right.replaceAll("0","");            int result = left.length()+right.length();            if(result > max) max = result;        }        return max;    }}``
{"ft_lang_label":"__label__en","ft_lang_prob":0.5968843,"math_prob":0.99969506,"size":1117,"snap":"2023-14-2023-23","text_gpt3_token_len":335,"char_repetition_ratio":0.19946092,"word_repetition_ratio":0.0,"special_character_ratio":0.39749327,"punctuation_ratio":0.1779661,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9997285,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-06-06T13:46:55Z\",\"WARC-Record-ID\":\"<urn:uuid:fb369e4a-3422-405b-be1e-b3f0dcf43c79>\",\"Content-Length\":\"29685\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:b2ee6c6c-1f87-437f-92c9-3d078c7785f9>\",\"WARC-Concurrent-To\":\"<urn:uuid:75c07787-eb0f-4e9b-8553-c0c1807bc523>\",\"WARC-IP-Address\":\"160.153.0.193\",\"WARC-Target-URI\":\"https://devopspal.com/2020/04/leetcode-strings-maximum-score-after-splitting-a-string/?amp=1\",\"WARC-Payload-Digest\":\"sha1:FVVFDECRSRFLMMQTZ5G4QJZKVLWDL2DF\",\"WARC-Block-Digest\":\"sha1:5HIKQUQR2Q6SZECEIVGQKXM2JER7DUUA\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224652569.73_warc_CC-MAIN-20230606114156-20230606144156-00272.warc.gz\"}"}