DP BOTTOM UP O(N) , JAVA, EASY
\nclass Solution {\n    public int numberOfUniqueGoodSubsequences(String s) {\n        int n=s.length();\n        int mod=(int)1e9+7;\n        int dp[]=new int[
```\nclass Solution {\n    public int numberOfUniqueGoodSubsequences(String s) {\n        int n=s.length();\n        int mod=(int)1e9+7;\n        int dp[]=new int[n+1];\n        int x=-1,y=-1,flag=0;\n        if(s.charAt(0)==\'1\') {\n            y=0;\n            dp[1]=1;\n        }\n        else\n            flag=1;\n        if(n==1) return 1;\n        for(int i=2;i<=n;i++)\n        {\n            char ch=s.charAt(i-1);\n            if(ch==\'0\' && y==-1)\n            continue;\n            dp[i]=(2*dp[i-1])%mod;\n            if(ch==\'1\')\n            {\n                if(y==-1)\n                    dp[i]=(dp[i]+1)%mod;\n                else\n                  dp[i]=(dp[i]-dp[y]+mod)%mod;\n                y=i-1;\n            }           \n           else\n           {\n               flag=1;\n                if(x!=-1)\n                  dp[i]=(dp[i]-dp[x]+mod)%mod;\n                x=i-1;\n           }\n           \n        }\n        return flag==1?dp[n]+1:dp[n];\n    }\n}\n```
[]