Minimum number of Appends of X or Y characters from the end to the front required to obtain given string | C # program for the above approach ; Function to find the minimum operations required to get the given string after appending m or n characters from the end to the front of the string in each operation ; Store the original string ; Stores the count of operations ; Traverse the string ; Cut m letters from end ; Add cut m letters to beginning ; Update j ; Check if strings are the same ; Cut n letters from end ; Add cut n letters to beginning ; Update j ; Check if strings are the same ; Update the turn ; Driver Code ; Given string S ; Function Call
using System ; class GFG { static void minimumOperations ( string orig_str , int m , int n ) { string orig = orig_str ; int turn = 1 ; int j = 1 ; for ( int i = 0 ; i < orig_str . Length ; i ++ ) { string m_cut = orig_str . Substring ( orig_str . Length - m ) ; orig_str = orig_str . Substring ( 0 , orig_str . Length - m ) ; orig_str = m_cut + orig_str ; j = j + 1 ; if ( ! orig . Equals ( orig_str ) ) { turn = turn + 1 ; String n_cut = orig_str . Substring ( orig_str . Length - n ) ; orig_str = orig_str . Substring ( 0 , orig_str . Length - n ) ; orig_str = n_cut + orig_str ; j = j + 1 ; } if ( orig . Equals ( orig_str ) ) { break ; } turn = turn + 1 ; } Console . WriteLine ( turn ) ; } public static void Main ( ) { string S = " GeeksforGeeks " ; int X = 5 , Y = 3 ; minimumOperations ( S , X , Y ) ; } }