Find the GCD of an array made up of numeric strings | Recursive function to return gcd of A and B ; Base case ; Length of A is greater ; Calculate GCD ; Store the GCD of the length of the strings ; Driver Code ; Function call
def GCD ( lena , lenb ) : NEW_LINE INDENT if ( lena == 0 ) : NEW_LINE INDENT return lenb NEW_LINE DEDENT if ( lenb == 0 ) : NEW_LINE INDENT return lena NEW_LINE DEDENT if ( lena == lenb ) : NEW_LINE INDENT return lena NEW_LINE DEDENT if ( lena > lenb ) : NEW_LINE INDENT return GCD ( lena - lenb , lenb ) NEW_LINE DEDENT return GCD ( lena , lenb - lena ) NEW_LINE DEDENT def StringGCD ( a , b ) : NEW_LINE INDENT gcd = GCD ( len ( a ) , len ( b ) ) NEW_LINE if a [ : gcd ] == b [ : gcd ] : NEW_LINE INDENT if a * ( len ( b ) // gcd ) == b * ( len ( a ) // gcd ) : NEW_LINE return a [ : gcd ] NEW_LINE DEDENT return - 1 NEW_LINE DEDENT a = ' geeksgeeks ' NEW_LINE b = ' geeks ' NEW_LINE print ( StringGCD ( a , b ) ) NEW_LINE