Skip to content

Practice Number of Ways to Split a String

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1573
LeetCode Problem

Number of Ways to Split a String

Problem Statement

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.

Source: Number of Ways to Split a String on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "10101"
Output
4

# Example 2

Input
s = "1001"
Output
0

# Example 3

Input
s = "0000"
Output
3

Constraints

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

Related LeetCode Problems

Practice more problems similar to Number of Ways to Split a String.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.