Simple O(N) DP
\nclass Solution {\npublic:\n    const int mod = 1e9 + 7;\n    \n    int numberOfUniqueGoodSubsequences(string s) {\n        int n = s.size();\n        vector<i
```\nclass Solution {\npublic:\n    const int mod = 1e9 + 7;\n    \n    int numberOfUniqueGoodSubsequences(string s) {\n        int n = s.size();\n        vector<int> dp(n, 0);\n        int zeroPos, onePos, start;\n        bool zeroPresent = false;\n        start = zeroPos = onePos = 0;\n        \n        while(start < n && s[start] == \'0\') start++;\n        \n        if(start == n) return 1;\n        \n        dp[start] = 1;\n        \n        for(int i = start + 1; i < n; i++) {\n            int j = (s[i] == \'0\' ? zeroPos : onePos);\n            dp[i] = (dp[i - 1] * 2 % mod - (j > 0 ? dp[j - 1] : 0) + mod) % mod;\n            if(s[i] == \'0\') zeroPos = i;\n            else onePos = i;\n        }\n        \n        zeroPresent |= count(begin(s), end(s), \'0\');\n        return dp[n - 1] + zeroPresent;\n    }\n};\n```
[]