Python - Greedy strategy, use 3 variables. O(n) time O(1) space
Idea:\n\n If we\'re in the middle of processing the string and see a \'1\', no new subsequences are created from old subsequences that we had before the last \'
**Idea:**\n\n* If we\'re in the middle of processing the string and see a \'1\', no new subsequences are created from old subsequences that we had **before** the last \'1\'. \n* However, all the new subsequences that were created since the last \'1\' **do create one** new subsequence each.\n* The same is true for \'0\'. So just track these three variables; the only edge case is if there are no zeros or no ones.\n\n\n```python\nclass Solution:\n    def numberOfUniqueGoodSubsequences(self, binary: str) -> int:\n        mod = 10 ** 9 + 7\n        n = len(binary)\n        first_one = binary.find(\'1\')\n        if first_one < 0:  # If no ones\n            return 1\n\n        if \'0\' not in binary:  # If no zeros\n            return n % mod\n\n        total = new_since_last_0 = new_since_last_1 = 1\n\n        for x in binary[first_one + 1:]:  # Start counting after the first 1\n            if x == \'1\':\n                new_since_last_0 += new_since_last_1\n                total += new_since_last_1\n            else:\n                new_since_last_1 += new_since_last_0\n                total += new_since_last_0\n            total %= mod\n            new_since_last_0 %= mod\n            new_since_last_1 %= mod\n\n        return (total + 1) % mod  # Add 1 for the single zero\n```
[]