Check if given string satisfies the following conditions | C # program for the above approach ; Function to check if given string satisfies the given conditions ; Dimensions ; Left diagonal ; Right diagonal ; Conditions not satisfied ; Print Yes ; Driver code ; Given String ; Function call
using System ; class GFG { static void isValid ( string s ) { int n = ( int ) Math . Sqrt ( s . Length ) ; char check = s [ 0 ] ; for ( int i = 0 ; i < n ; i ++ ) { int x = i , y = i ; while ( x >= 0 && y < n ) { if ( s [ ( n * x ) + y ] != check || s [ ( n * y ) + x ] != check ) { Console . Write ( " No " ) ; return ; } x -- ; y ++ ; } } Console . Write ( " Yes " ) ; } public static void Main ( ) { string str = " abacdaeaafaghaia " ; isValid ( str ) ; } }