Check whether two strings are equivalent or not according to given condition | C # Program to find whether two strings are equivalent or not according to given condition ; This function returns the least lexicogr - aphical String obtained from its two halves ; Base Case - If String size is 1 ; Divide the String into its two halves ; Form least lexicographical String ; Driver Code
using System ; class GFG { static String leastLexiString ( String s ) { if ( s . Length == 1 ) return s ; String x = leastLexiString ( s . Substring ( 0 , s . Length / 2 ) ) ; String y = leastLexiString ( s . Substring ( s . Length / 2 ) ) ; return ( ( x + y ) . CompareTo ( y + x ) . ToString ( ) ) ; } static Boolean areEquivalent ( String a , String b ) { return ! ( leastLexiString ( a ) . Equals ( leastLexiString ( b ) ) ) ; } public static void Main ( String [ ] args ) { String a = " aaba " ; String b = " abaa " ; if ( areEquivalent ( a , b ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; a = " aabb " ; b = " abab " ; if ( areEquivalent ( a , b ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } }