Check if it is possible to create a palindrome string from given N | C # implementation of the above approach ; Function to check if a string is palindrome or not ; String that stores characters of s in reverse order ; Length of the string s ; String used to form substring using N ; Variable to store sum of digits of N ; Forming the substring by traversing N ; Appending the substr to str till it 's length becomes equal to sum ; Trimming the string str so that it 's length becomes equal to sum ; Driver code ; Calling function isPalindrome to check if str is Palindrome or not
using System ; class GFG { static bool isPalindrome ( String s ) { String s1 = " " ; int N = s . Length ; for ( int i = N - 1 ; i >= 0 ; i -- ) s1 += s [ i ] ; if ( s . Equals ( s1 ) ) return true ; return false ; } static bool createString ( int N ) { String str = " " ; String s = " " + N ; String letters = " abcdefghij " ; int sum = 0 ; String substr = " " ; for ( int i = 0 ; i < s . Length ; i ++ ) { int digit = s [ i ] - '0' ; substr += letters [ digit ] ; sum += digit ; } while ( str . Length <= sum ) { str += substr ; } str = str . Substring ( 0 , sum ) ; return isPalindrome ( str ) ; } public static void Main ( ) { int N = 61 ; bool flag = createString ( N ) ; if ( flag ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } }