Class Solution
-
- All Implemented Interfaces:
public final class Solution
2851 - String Transformation\.
Hard
You are given two strings
s
andt
of equal lengthn
. You can perform the following operation on the strings
:Remove a suffix of
s
of lengthl
where0 < l < n
and append it at the start ofs
. For example, lets = 'abcd'
then in one operation you can remove the suffix'cd'
and append it in front ofs
makings = 'cdab'
.
You are also given an integer
k
. Return the number of ways in whichs
can be transformed intot
in exactlyk
operations.Since the answer can be large, return it modulo <code>10<sup>9</sup> + 7</code>.
Example 1:
Input: s = "abcd", t = "cdab", k = 2
Output: 2
Explanation:
First way:
In first operation, choose suffix from index = 3, so resulting s = "dabc".
In second operation, choose suffix from index = 3, so resulting s = "cdab".
Second way:
In first operation, choose suffix from index = 1, so resulting s = "bcda".
In second operation, choose suffix from index = 1, so resulting s = "cdab".
Example 2:
Input: s = "ababab", t = "ababab", k = 1
Output: 2
Explanation:
First way:
Choose suffix from index = 2, so resulting s = "ababab".
Second way:
Choose suffix from index = 4, so resulting s = "ababab".
Constraints:
<code>2 <= s.length <= 5 * 10<sup>5</sup></code>
<code>1 <= k <= 10<sup>15</sup></code>
s.length == t.length
s
andt
consist of only lowercase English alphabets.