Skip to content

Practice Find All 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.

Hard#1397
LeetCode Problem

Find All Good Strings

Problem Statement

Given the strings s1 and s2 of size n and the string evil, return the number of good strings. A good string has size n, it is alphabetically greater than or equal to s1, it is alphabetically smaller than or equal to s2, and it does not contain the string evil as a substring. Since the answer can be a huge number, return this modulo 10^9 + 7.

Source: Find All Good Strings on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 2, s1 = "aa", s2 = "da", evil = "b"
Output
51

# Example 2

Input
n = 8, s1 = "leetcode", s2 = "leetgoes", evil = "leet"
Output
0

# Example 3

Input
n = 2, s1 = "gx", s2 = "gz", evil = "x"
Output
2

Constraints

s1.length == n
s2.length == n
s1 <= s2
1 <= n <= 500
1 <= evil.length <= 50
All strings consist of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Find All Good Strings.

Review your practice with PhantomCodeAI

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