You are given a binary string binary. A subsequence of binary is considered good if it is not empty and has no leading zeros (with the exception of "0").
Find the number of unique good subsequences of binary.
For example, if binary = "001", then all the good subsequences are ["0", "0", "1"], so the unique good subsequences are "0" and "1". Note that subsequences "00", "01", and "001" are not good because they have leading zeros.
Return _the number ofunique good subsequences of _binary. Since the answer may be very large, return it modulo10^9 + 7.
A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.
Input: binary ="101" Output:5 Explanation: The good subsequences of binary are ["1","0","1","10","11","101"]. The unique good subsequences are "0","1","10","11", and "101".
We want to count all unique good subsequences (no leading zeros except for “0”). For each character, we can keep track of the number of unique good subsequences ending with ‘0’ and ‘1’. If we see a ‘1’, it can start a new good subsequence or extend any previous good subsequence. If we see a ‘0’, it can only extend previous good subsequences ending with ‘1’, but a single ‘0’ is also allowed. We use DP to avoid duplicates.