Go solution with Runtime 26 ms  Beats 100.00% of users with Go
Approach\n\n1. Initialization: Initialize necessary variables, including count to store the count of unique good subsequences ending at each position, occurrenc
# Approach\n\n**1. Initialization:** Initialize necessary variables, including count to store the count of unique good subsequences ending at each position, occurrence to track the occurrences of \'0\'s and \'1\'s, lastPosition to store the last position of \'0\'s and \'1\'s encountered, and firstZeroLoc to track the first occurrence of \'0\' in the binary string.\n\n**2. Main Loop:**\n\n- Iterate over each character in the binary string.\n- Update occurrence, lastPosition, and firstZeroLoc based on the current character.\n- For each character, compute the count of unique good subsequences ending at the current position.\n- Store the count in the count array.\n\n**3. Sum Calculation:**\n\n- After processing all characters, compute the total count of unique good subsequences.\n- Sum up all counts stored in the count array, taking care of the modulo operation to prevent integer overflow.\n\n**4. Return:**\n- Return the total count of unique good subsequences.\n\n# Complexity\n\n- **Time complexity:**\n    - The program iterates over each character in the binary string once, resulting in a time complexity of O(N), where N is the length of the binary string.\n    - Within each iteration, the program performs constant-time operations.\n    - Overall, the time complexity is O(N).\n\n- **Space complexity:**\n    - The program uses additional space to store the count array, occurrence, lastPosition, and a few other variables.\n    - The space complexity is O(N) to store the count array and O(1) for other variables.\n    - Overall, the space complexity is O(N).\n# Code\n```\nconst MOD = 1000000007\n\nfunc numberOfUniqueGoodSubsequences(binary string) int {\n\tcount := make([]int, len(binary))\n\toccurrence := [2]int{0, 0}\n\tlastPosition := [2]int{-1, -1}\n\tfirstZeroLoc := -1\n\n\tfor i, ch := range binary {\n\t\tidx := int(ch - \'0\')\n\t\tif firstZeroLoc == -1 && ch == \'0\' {\n\t\t\tfirstZeroLoc = i\n\t\t}\n\n\t\tif i == 0 {\n\t\t\toccurrence[idx]++\n\t\t\tlastPosition[idx] = 0\n\t\t\tcount[0] = 1\n\t\t\tcontinue\n\t\t}\n\n\t\tvar sum int64 = 0\n\n\t\tif occurrence[idx] == 0 {\n\t\t\tsum++\n\t\t}\n\n\t\tstart := max(0, lastPosition[idx])\n\t\tsum += int64(getSum(count, start, i, firstZeroLoc))\n\t\tsum %= MOD\n\n\t\tlastPosition[idx] = i\n\t\toccurrence[idx]++\n\t\tcount[i] = int(sum)\n\t}\n\n\tvar ans int64 = 0\n\tfor _, c := range count {\n\t\tans += int64(c)\n\t\tans %= MOD\n\t}\n\treturn int(ans)\n}\n\nfunc getSum(count []int, start, end, firstZeroLoc int) int {\n\tvar sum int64 = 0\n\tfor i := start; i < end; i++ {\n\t\tif i == firstZeroLoc {\n\t\t\tif count[i]-1 == 0 {\n\t\t\t\tsum += MOD\n\t\t\t} else {\n\t\t\t\tsum += int64(count[i] - 1)\n\t\t\t}\n\t\t} else {\n\t\t\tsum += int64(count[i])\n\t\t}\n\t\tsum %= MOD\n\t}\n\treturn int(sum)\n}\n\nfunc max(a, b int) int {\n\tif a > b {\n\t\treturn a\n\t}\n\treturn b\n}\n\n```
['Go']