hardDynamic ProgrammingString 0 views

Number of Unique Good Subsequences

You are given a binary string binary.

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.

Return the number of unique good subsequences of binary. Since the answer may be very large, return it modulo 10^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.

Number of Unique Good Subsequences diagram

Example 1

Input: binary = "001"

Output: 2

Explanation: The good subsequences of binary are ["0", "0", "1"]. The unique good subsequences are "0" and "1".

Example 2

Input: binary = "11"

Output: 2

Explanation: The good subsequences of binary are ["1", "1", "11"]. The unique good subsequences are "1" and "11".

Example 3

Input: binary = "10^1"

Output: 5

Explanation: The good subsequences of binary are ["1", "0", "1", "10", "11", "10^1"]. The unique good subsequences are "0", "1", "10", "11", and "10^1".

Constraints

  • 1 <= binary.length <= 10^5
  • binary consists of only '0's and '1's.

Hints

Companies

No companies reported yet.

Discussion

Sign in to join the discussion.

Loading discussion...

Test results

No test cases yet.