Mid/SeniorMathString

Number of Ways to Split a String

Given a binary string s, you can split s into 3 non-empty strings s1, s2, and s3 where s1 + s2 + s3 = s.

Return the number of ways s can be split such that the number of ones is the same in s1, s2, and s3. Since the answer may be too large, return it modulo 10^9 + 7.

Example 1
Inputs = "10101"
Output4
There are four ways to split s into 3 parts where each part contains the same number of letters '1'.
Example 2
Inputs = "1001"
Output0
There is no way to split s into 3 non-empty parts with the same number of ones.

Constraints

  • 3 <= s.length <= 10^5
  • s[i] is either '0' or '1'.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate