C++  DP Solution O(N) Space & O(1) Solutions
```\n*O(N) Space \nclass Solution {\npublic:\n    int numberOfUniqueGoodSubsequences(string binary) {\n        int N = binary.length();\n        const int MOD =
```\n*****O(N) Space ****\nclass Solution {\npublic:\n    int numberOfUniqueGoodSubsequences(string binary) {\n        int N = binary.length();\n        const int MOD = 1e9 + 7;\n        vector<int> dp(N+1, 0);\n        vector<int> last(2, -1);\n        \n        dp[0] = 1;\n        for(int i = 0; i < N; i++){\n            int x = binary[i] - \'0\';\n            dp[i+1] = dp[i] * 2 %MOD;\n            \n            if(last[x] >= 0){\n                dp[i+1] = dp[i+1] - dp[last[x]];\n            }\n            else if(x == 0){\n                dp[i+1] -= 1;\n            }\n            dp[i+1] = dp[i+1] >= 0 ? dp[i+1]%MOD : dp[i+1]+MOD;\n            last[x] = i;\n        }\n        \n        dp[N]--;\n        \n        if(last[0] >= 0){\n            dp[N]++;\n        }\n        \n        return dp[N];\n    }\n};\n\n*******O(1) Space********\nclass Solution {\npublic:\n    int numberOfUniqueGoodSubsequences(string binary) {\n        int N = binary.length();\n        const int MOD = 1e9 + 7;\n        vector<int> last(2, -1);\n        \n        int prev = 1;\n        int curr = 0;\n        for(int i = 0; i < N; i++){\n            int x = binary[i] - \'0\';\n            curr = prev * 2 %MOD;\n            \n            if(last[x] >= 0){\n                curr = curr - last[x];\n            }\n            else if(x == 0){\n                curr -= 1;\n            }\n            curr = curr >= 0 ? curr%MOD : curr+MOD;\n            last[x] = prev;\n            prev = curr;\n        }\n        \n        curr--;\n        \n        if(last[0] >= 0){\n            curr++;\n        }\n        \n        return curr;\n    }\n};
['C']