DP  O(N) time, O(1) space
\nclass Solution {\npublic:\n    int numberOfUniqueGoodSubsequences(string s) \n    {\n        int n=s.length(),i=0,mod=1e9+7;\n        int ans=1,one=0,zero=-1,
```\nclass Solution {\npublic:\n    int numberOfUniqueGoodSubsequences(string s) \n    {\n        int n=s.length(),i=0,mod=1e9+7;\n        int ans=1,one=0,zero=-1,z=0;\n        \n        while(i<n && s[i]==\'0\') i++,z=1;\n        if(i==n) return z;\n        \n        i++;\n        while(i<n)\n        {\n            int lst=ans;\n            ans=(ans*2)%mod;\n            \n            if(s[i]==\'0\' && zero!=-1) ans=(ans-zero+mod)%mod;\n            else if(s[i]==\'1\' && one!=-1) ans=(ans-one+mod)%mod;\n            \n            if(s[i]==\'1\') one=lst;\n            else zero=lst,z=1;\n            \n            i++;\n        }\n        return (ans+z)%mod;\n    }\n};\n```
['Dynamic Programming', 'C', 'C++']