Minimum move to end operations to make all strings equal | C # program to make all strings same using move to end operations . ; Returns minimum number of moves to end operations to make all strings same . ; Consider s [ i ] as target string and count rotations required to make all other strings same as str [ i ] . ; find function returns the index where we found arr [ i ] which is actually count of move - to - front operations . ; If any two strings are not rotations of each other , we can 't make them same. ; Driver code
using System ; public class GFG { public static int minimunMoves ( string [ ] arr , int n ) { int ans = int . MaxValue ; for ( int i = 0 ; i < n ; i ++ ) { int curr_count = 0 ; string tmp = " " ; for ( int j = 0 ; j < n ; j ++ ) { tmp = arr [ j ] + arr [ j ] ; int index = tmp . IndexOf ( arr [ i ] , StringComparison . Ordinal ) ; if ( index == arr [ i ] . Length ) { return - 1 ; } curr_count += index ; } ans = Math . Min ( curr_count , ans ) ; } return ans ; } public static void Main ( string [ ] args ) { string [ ] arr = new string [ ] { " xzzwo " , " zwoxz " , " zzwox " , " xzzwo " } ; int n = arr . Length ; Console . WriteLine ( minimunMoves ( arr , n ) ) ; } }