1987. Number of Unique Good Subsequences
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public int numberOfUniqueGoodSubsequences(String input) {
        int constant = (int) 1e9 + 7;
        int zeroEnd = 0;
        int oneEnd = 0;
        int flagZero = 0;

        for (int idx = 0; idx < input.length(); idx++) {
            if (input.charAt(idx) == '0') {
                zeroEnd = (zeroEnd + oneEnd) % constant;
                flagZero = 1;
            } else {
                oneEnd = (zeroEnd + oneEnd + 1) % constant;
            }
        }

        return (zeroEnd + oneEnd + flagZero) % constant;
    }
}

```
['Java']