#K33362. Minimum Left Rotations to Equal Strings
Minimum Left Rotations to Equal Strings
Minimum Left Rotations to Equal Strings
Given two strings s
and t
each of length \( n \), determine the minimum number of left rotations required to transform s
into t
. A left rotation moves the first character of the string to its end (i.e. \( s = s_1s_2\ldots s_n \) becomes \( s_2\ldots s_ns_1 \)).
If it is not possible to obtain t
from s
by any sequence of left rotations, print \(-1\).
Note: It is guaranteed that \( s \) and \( t \) consist of only lowercase English letters.
inputFormat
The input is read from standard input and consists of three lines:
- An integer
n
representing the length of the strings. - A string
s
of lengthn
. - A string
t
of lengthn
.
It is guaranteed that \( 1 \leq n \leq 10^5 \).
outputFormat
Output a single integer representing the minimum number of left rotations required to transform s
into t
. If it is impossible, output -1
.
The output should be written to standard output.
## sample4
abcd
bcda
1