Dynamic programming
IntuitionIdea: Divide the problem into subproblems and save the solution of subproblems in array.Let "ugs" be an array which stores the unique good subseq.at ev
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

Idea: Divide the problem into subproblems and save the solution of subproblems in array.

Let "ugs" be an array which stores the unique good subseq.at every index from right.

That means ugs[i] will have unique good subs. starting with binary[i].



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

Subproblem => to calculate ugs[i] we have to compare {binary[i], ugs[i +1] }

Equation 
    ugs[i] = Summation of u[k] where  k = {i + 1, i + 2, ... l} &  l must be the first index to match binary[i] == binary[l] or l = n - 1


Proof: 
    if binary[i] == binary[l] for some l then ..
        ugs formed with binary[i] must eq. ugs formed with binary[l]
  
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(n)

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

# Code
```typescript []
function numberOfUniqueGoodSubsequences(binary: string): number {
    const mod7  = Math.pow(10,9) + 7;
    const ugs = new Array<number>(binary.length);
    let sum = 0;
    let i = 0;
    while (i < binary.length) {
      ugs[i] = 0;
      if (binary[i] !== "1") {
        sum = 1;
        i++;
      } else break;
    }
    if (i === binary.length) return 1;
    if (binary[binary.length - 1] !== "1") sum = 1;

    let l = binary.length - 1;
    const charc = binary[l];
    while (l > i) {
      if (binary[l] === charc) {
        ugs[l] = 1;
        l--;
      } else {
        ugs[l] = binary.length - l;
        sum = 1;
        l--;
        break;
      }
    }

    for (let j = l; j > i; j--) {
      if (binary[j] !== "1") sum = 1;
      let k = j + 1;
      let sb = 0;
      while (k < binary.length) {
        sb += ugs[k];
        sb %= mod7;
        if (binary[j] === binary[k]) break;
        else k++;
      }
      ugs[j] = sb;
    }

    return ugs.reduce((prv, curv) => (prv + curv) % mod7, sum + 1);
  
};
```
['TypeScript']