Search Results
7/25/2025, 10:32:33 PM
>>106003058
>Fact 1
The string decomposes into "blocks" consisting of a,b and "separators" consisting of any other characters.
>Fact 2
The separators never change, so we can consider each block individually and add their scores up at the end.
>Fact 3
Within each block, we will use up all the a's or all the b's, whichever are fewer. (This uses the constraint that x,y>0, which you didn't post but it's listed on leetcode.)
>Fact 4
Might as well scan across the whole string, identifying blocks and greedily preferring x if x>y or y if y>x; just needs a few variables and we're done.
O(n) time O(1) space
>Fact 1
The string decomposes into "blocks" consisting of a,b and "separators" consisting of any other characters.
>Fact 2
The separators never change, so we can consider each block individually and add their scores up at the end.
>Fact 3
Within each block, we will use up all the a's or all the b's, whichever are fewer. (This uses the constraint that x,y>0, which you didn't post but it's listed on leetcode.)
>Fact 4
Might as well scan across the whole string, identifying blocks and greedily preferring x if x>y or y if y>x; just needs a few variables and we're done.
O(n) time O(1) space
7/3/2025, 4:29:06 PM
Page 1