Welcome to AlgoYogi!
🚀 Start Your Smart Coding Prep at 👉 https://algoyogi.io
We solve LeetCode 1422: Maximum Score After Splitting a String using a clean linear approach.
Given a binary string s, choose a split between characters to maximize:
score = number of zeros on the left plus number of ones on the right.
Approach:
- Precount total_ones in s
- Scan from left to right, maintaining zeros_left and ones_right
- At each split position i (between i and i+1), update:
ones_right = total_ones minus ones_seen_so_far
candidate = zeros_left plus ones_right
track the maximum
- Ensure the split leaves both sides nonempty
👉 Problem Link: https://leetcode.com/problems/maximum-score-after-splitting-a-string/
---
### ⏱ Timestamps
0:00 Introduction
0:20 Problem Statement
0:40 Prefix and Suffix Counting
13:00 Python Code Walkthrough
15:00 Time and Space Complexity
---
### 💡 Why Watch?
- One pass, O(n) time and O(1) space
- Elegant use of running counts instead of recalculating per split
- Interview friendly with simple proof of correctness
#LeetCode #MaximumScoreAfterSplit #Python #AlgoYogi #PrefixSum #String
Download
0 formats
No download links available.
LeetCode 1422 | Maximum Score After Splitting a String | Python One-Pass Prefix/Suffix | AlgoYogi | NatokHD