HomeMaximize Number of Subsequences in a String 1 2 3 4 5 6 7 8 9 10 class Solution: def maximumSubsequenceCount(self, text, pattern): res = cnt1 = cnt2 = 0 for c in text: if c == pattern[1]: res += cnt1 cnt2 += 1 if c == pattern[0]: cnt1 += 1 return res + max(cnt1, cnt2)
1 2 3 4 5 6 7 8 9 10
class Solution: def maximumSubsequenceCount(self, text, pattern): res = cnt1 = cnt2 = 0 for c in text: if c == pattern[1]: res += cnt1 cnt2 += 1 if c == pattern[0]: cnt1 += 1 return res + max(cnt1, cnt2)