✅✅Faster || Easy To Understand || C++ Code
Using Dp\n\n Time Complexity :- O(N)\n\n Space Complexity :- O(1)\n\n\nclass Solution {\npublic:\n    int numberOfUniqueGoodSubsequences(string binary) {\n     
* ***Using Dp***\n\n* ***Time Complexity :- O(N)***\n\n* ***Space Complexity :- O(1)***\n\n```\nclass Solution {\npublic:\n    int numberOfUniqueGoodSubsequences(string binary) {\n        \n        int n = binary.size();\n        \n        long long mod = 1e9 + 7;\n        \n        // dp[i][j] will tell us no. of subsequence starting with i and ending with j\n        \n        // dp[0][1] will be always 0, because "01" is invalid\n        \n        vector<vector<int>> dp(2, vector<int> (2, 0));\n        \n        for(int i = 0; i < n; i++)\n        {\n            if(binary[i] == \'0\')\n            {\n                // no. of subsequence starting with 0 and ending with 0 i.e "0"\n                \n                dp[0][0] = 1;\n                \n                // no. of subsequence starting with 1 and ending with 0\n                \n                dp[1][0] = (dp[1][0] % mod + dp[1][1] % mod) % mod;\n            }\n            else\n            {\n                // no. of subsequence starting with 1 and ending with 1\n                \n                dp[1][1] = (dp[1][0] % mod + dp[1][1] % mod + 1 % mod) % mod;\n            }\n        }\n        \n        return (dp[0][0] % mod + dp[1][0] % mod + dp[1][1] % mod) % mod;\n    }\n};\n```
['Dynamic Programming', 'C', 'C++']