Skip to content

Practice Count Ways To Build Good Strings

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

Medium#2466
LeetCode Problem

Count Ways To Build Good Strings

Problem Statement

Start empty and repeatedly append the character 0 exactly zero times, or the character 1 exactly one times, where zero and one are the given positive block lengths. Count distinct resulting strings with length from low through high inclusive. Return the count modulo 10^9 + 7.

Source: Count Ways To Build Good Strings on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
low = 3, high = 3, zero = 1, one = 1
Output
8

# Example 2

Input
low = 2, high = 3, zero = 1, one = 2
Output
5

Constraints

1 <= low <= high <= 10^5
1 <= zero, one <= low

Related LeetCode Problems

Practice more problems similar to Count Ways To Build Good Strings.

Review your practice with PhantomCodeAI

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