String Transformation

You are given two strings s and t of equal length n. You can perform the following operation on the string s:

  • Remove a suffix of s of length l where 0 < l < n and append it at the start of s.

Return the number of ways in which s can be transformed into t in exactly k operations.

Since the answer can be large, return it modulo 10^9 + 7.

Example 1
Inputs = "abcd", t = "cdab", k = 2
Output2
There are two valid sequences of operations: choosing the suffix from index 3 in both operations, or choosing the suffix from index 1 in both operations.
Example 2
Inputs = "ababab", t = "ababab", k = 1
Output2
There are two suffix choices, from index 2 or index 4, that transform s back into t in one operation.

Constraints

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

Asked at 3 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