Skip to content

Practice String Transformation

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

Hard#2851
LeetCode Problem

String Transformation

Problem Statement

s and t have the same length n. One operation chooses a suffix of length from 1 through n - 1 and moves it to the front, preserving the order within both pieces. Return how many sequences of exactly k operations turn s into t, modulo 10^9 + 7.

Source: String Transformation on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "abcd", t = "cdab", k = 2
Output
2

# Example 2

Input
s = "ababab", t = "ababab", k = 1
Output
2

Constraints

2 <= s.length <= 5 * 10^5
1 <= k <= 10^15
s.length == t.length
s and t consist of only lowercase English alphabets.

Related LeetCode Problems

Practice more problems similar to String Transformation.

Review your practice with PhantomCodeAI

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