# 22.12.2023 [1422. Maximum Score After Splitting a String]
Max left_zeros + right_ones in 01-array
22.12.2023
1422. Maximum Score After Splitting a String easy
blog post
Join me on Telegram
https://t.me/leetcode_daily_unstoppable/447
Problem TLDR
Max left_zeros + right_ones in 01-array
Intuition
We can count ones
and then scan from the beginning modifying the ones
and zeros
counts. After some retrospect, we can do this with score
variable.
Complexity
Time complexity:
O(n)Space complexity:
O(1), dropLast(1) creates the second list, but we can just use pointers orasSequence
Code
fun maxScore(s: String): Int {
var score = s.count { it == '1' }
return s.dropLast(1).maxOf {
if (it == '0') ++score else --score
}
}