java simple solution| O(n) with detailed explanation
Refer: https://www.codingninjas.com/codestudio/library/number-of-unique-good-subsequences\nConsider two variables, say, \u201CendsWithZero\u201D and \u201CendsW
Refer: https://www.codingninjas.com/codestudio/library/number-of-unique-good-subsequences\nConsider two variables, say, \u201CendsWithZero\u201D and \u201CendsWithOne\u201D to keep the count of the number of subsequences ending with 0 and 1, respectively.\n\nDefine a flag \u201ChasZero\u201D to check if the given binary string contains \u20180\u2019 or not.\n\nTraverse the binary string and update the values of \u201CendsWithZero\u201D and \u201CendsWithOne\u201D in this manner - \n\nIf the current character is \u20181\u2019, then you can - \n\nAppend it to all the subsequences ending with \u20180\u2019 and ending with \u20181\u2019. In this way, you get the total number of subsequences ending with \u20181\u2019 till now. \n\nOr You chose not to append this \u20181\u2019 to the previous subsequences and consider it a subsequence of a single character, i.e. the subsequence \u20181\u2019, which is also a valid unique good subsequence.\n\nSo, we update endsWithOne as follows:\n\nendsWithOne = endsWithOne + endsWithZero + 1\n\nIf the current character is \u20180\u2019, then -\n\nAppend it to the subsequences ending with \u20180\u2019 and ending with \u20181\u2019. In this way, you get the total number of subsequences ending with \u20180\u2019 till now. \n\nThe subsequence \u20180\u2019 is also valid. But we will not increase the count by one every time we encounter \u20180\u2019. Instead, we will add 1 for this subsequence only once at the end. Why? Shortly, we will see a dry run of this approach which will help you understand the reason behind this.\n\nSo, we update endsWithZero as follows:\n\nendsWithZero = endsWithOne + endsWithZero\n\n \n\nCalculate the total number of unique good subsequences  as follows:\n\nnumberOfUniquegoodSubsequences = endsWithOne +  endsWithZero + hasZero\n\n\n```\nclass Solution {\n    public int numberOfUniqueGoodSubsequences(String binary) {\n        // if current char is 1 dp[i] = 2* dp[i-1]\n        // if current character is zero dp[i] = 2*(dp[i-1]-1);\n        int endsWithOne = 0;\n        int endsWithTwo = 0;\n        int MOD = 1_000_000_007;\n        int hasZero = 0;\n        for(int i=0; i<binary.length();i++){\n            if(binary.charAt(i)==\'1\'){\n                endsWithOne = (endsWithOne + endsWithTwo + 1)%MOD;\n            }else{\n                hasZero = 1;\n                endsWithTwo = (endsWithOne + endsWithTwo)%MOD;\n            }\n        }\n        int ans = (endsWithOne + endsWithTwo + hasZero)%MOD;\n        \n        return ans;\n    }\n}\n```\n
['Dynamic Programming', 'Java']