Monday, March 9, 2020

HackWithInfy Problem | Minimum String Rotation

“Minimum String Rotation” 

A rotation on a string is defined as removing first element and concatenating it at the end.
Given a number N and N strings .
Output the minimum no. of rotations on the strings so as to make all the strings equal.
If this is not possible print -1.

Input 
4
11234
34112
41123
11234

Output
3

finally all the strings would be 11234
first and last string input needs no rotations.
second needs 2 rotations.
third needs 1 rotation.
So total rotation will be 3.

No comments:

Post a Comment