codeparrot/xlcost-text-to-code huggingface dataset:
Find numbers of balancing positions in string | C # program to find number of balancing points in string ; method to return number of balancing points ; hash array for storing hash of string initialized by 0 being global ; process string initially for rightVisited ; check for balancing points ; for every position inc left hash & dec rightVisited ; check whether both hash have same character or not ; Either both leftVisited [ j ] and rightVisited [ j ] should have none zero value or both should have zero value ; if both have same character increment count ; Driver Code
using System ; class GFG { static int MAX_CHAR = 256 ; static int countBalance ( string s ) { int [ ] rightVisited = new int [ MAX_CHAR ] ; int [ ] leftVisited = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < n ; i ++ ) rightVisited [ s [ i ] ] ++ ; int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { leftVisited [ s [ i ] ] ++ ; rightVisited [ s [ i ] ] -- ; int j ; for ( j = 0 ; j < MAX_CHAR ; j ++ ) { if ( ( leftVisited [ j ] == 0 && rightVisited [ j ] != 0 ) || ( leftVisited [ j ] != 0 && rightVisited [ j ] == 0 ) ) break ; } if ( j == MAX_CHAR ) res ++ ; } return res ; } public static void Main ( String [ ] args ) { string str = " abaababa " ; Console . WriteLine ( countBalance ( str ) ) ; } }
Min flips of continuous characters to make all characters same in a string | C # program to find min flips in binary string to make all characters equal ; To find min number of flips in binary string ; If last character is not equal to str [ i ] increase res ; To return min flips ; Driver program to check findFlips ( )
using System ; public class GFG { static int findFlips ( String str , int n ) { char last = ' ▁ ' ; int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( last != str [ i ] ) res ++ ; last = str [ i ] ; } return res / 2 ; } public static void Main ( ) { String str = "00011110001110" ; int n = str . Length ; Console . Write ( findFlips ( str , n ) ) ; } }
Maximum length substring having all same characters after k changes | C # program to find maximum length equal character string with k changes ; method to find the maximum length of substring having character ch ; traverse the whole string ; if character is not same as ch increase count ; While count > k traverse the string again until count becomes less than k and decrease the count when characters are not same ; length of substring will be rightIndex - leftIndex + 1. Compare this with the maximum length and return maximum length ; method which returns maximum length of substring ; Driver Method
using System ; class GFG { public static int findLen ( string A , int n , int k , char ch ) { int maxlen = 1 ; int cnt = 0 ; int l = 0 , r = 0 ; while ( r < n ) { if ( A [ r ] != ch ) { ++ cnt ; } while ( cnt > k ) { if ( A [ l ] != ch ) { -- cnt ; } ++ l ; } maxlen = Math . Max ( maxlen , r - l + 1 ) ; ++ r ; } return maxlen ; } public static int answer ( string A , int n , int k ) { int maxlen = 1 ; for ( int i = 0 ; i < 26 ; ++ i ) { maxlen = Math . Max ( maxlen , findLen ( A , n , k , ( char ) ( i + ' A ' ) ) ) ; maxlen = Math . Max ( maxlen , findLen ( A , n , k , ( char ) ( i + ' a ' ) ) ) ; } return maxlen ; } public static void Main ( string [ ] args ) { int n = 5 , k = 2 ; string A = " ABABA " ; Console . WriteLine ( " Maximum ▁ length ▁ = ▁ " + answer ( A , n , k ) ) ; n = 6 ; k = 4 ; string B = " HHHHHH " ; Console . WriteLine ( " Maximum ▁ length ▁ = ▁ " + answer ( B , n , k ) ) ; } }
Quick way to check if all the characters of a string are same | C # program for above approach ; Function to check is all the characters in string are or not ; Insert characters in the set ; If all characters are same Size of set will always be 1 ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void allCharactersSame ( string s ) { HashSet < char > s1 = new HashSet < char > ( ) ; for ( int i = 0 ; i < s . Length ; i ++ ) s1 . Add ( s [ i ] ) ; if ( s1 . Count == 1 ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } static void Main ( ) { string str = " nnnn " ; allCharactersSame ( str ) ; } }
Find the character in first string that is present at minimum index in second string | C # implementation to find the character in first string that is present at minimum index in second string ; method to find the minimum index character ; to store the index of character having minimum index ; lengths of the two strings ; traverse ' patt ' ; for each character of ' patt ' traverse ' str ' ; if patt . charAt ( i ) is found in ' str ' , check if it has the minimum index or not . If yes , then update ' minIndex ' and break ; print the minimum index character ; if no character of ' patt ' is present in ' str ' ; Driver Methoda
using System ; class GFG { static void printMinIndexChar ( String str , String patt ) { int minIndex = int . MaxValue ; int m = str . Length ; int n = patt . Length ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( patt [ i ] == str [ j ] && j < minIndex ) { minIndex = j ; break ; } } } if ( minIndex != int . MaxValue ) Console . WriteLine ( " Minimum ▁ Index ▁ Character ▁ = ▁ " + str [ minIndex ] ) ; else Console . WriteLine ( " No ▁ character ▁ present " ) ; } public static void Main ( ) { String str = " geeksforgeeks " ; String patt = " set " ; printMinIndexChar ( str , patt ) ; } }
Find the character in first string that is present at minimum index in second string | C # implementation to find the character in first string that is present at minimum index in second string ; method to find the minimum index character ; map to store the first index of each character of ' str ' ; to store the index of character having minimum index ; lengths of the two strings ; store the first index of each character of ' str ' ; traverse the string ' patt ' ; if patt [ i ] is found in ' um ' , check if it has the minimum index or not , accordingly update ' minIndex ' ; print the minimum index character ; if no character of ' patt ' is present in ' str ' ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static void printMinIndexChar ( String str , String patt ) { Dictionary < char , int > hm = new Dictionary < char , int > ( ) ; int minIndex = int . MaxValue ; int m = str . Length ; int n = patt . Length ; for ( int i = 0 ; i < m ; i ++ ) if ( ! hm . ContainsKey ( str [ i ] ) ) hm . Add ( str [ i ] , i ) ; for ( int i = 0 ; i < n ; i ++ ) if ( hm . ContainsKey ( patt [ i ] ) && hm [ patt [ i ] ] < minIndex ) minIndex = hm [ patt [ i ] ] ; if ( minIndex != int . MaxValue ) Console . WriteLine ( " Minimum ▁ Index ▁ Character ▁ = ▁ " + str [ minIndex ] ) ; else Console . WriteLine ( " No ▁ character ▁ present " ) ; } public static void Main ( String [ ] args ) { String str = " geeksforgeeks " ; String patt = " set " ; printMinIndexChar ( str , patt ) ; } }
Check if both halves of the string have same set of characters | C # program to check if it two half of string contain same Character set or not ; function to check both halves for equality ; Counter array initialized with 0 ; Length of the string ; traverse till the middle element is reached ; First half ; Second half ; Checking if values are different set flag to 1 ; Driver program to test above function ; String to be checked
using System ; class GFG { static int MAX_CHAR = 26 ; static bool checkCorrectOrNot ( string s ) { int [ ] count1 = new int [ MAX_CHAR ] ; int [ ] count2 = new int [ MAX_CHAR ] ; int n = s . Length ; if ( n == 1 ) return true ; for ( int i = 0 , j = n - 1 ; i < j ; i ++ , j -- ) { count1 [ s [ i ] - ' a ' ] ++ ; count2 [ s [ j ] - ' a ' ] ++ ; } for ( int i = 0 ; i < MAX_CHAR ; i ++ ) if ( count1 [ i ] != count2 [ i ] ) return false ; return true ; } public static void Main ( ) { string s = " abab " ; if ( checkCorrectOrNot ( s ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Given a number as a string , find the number of contiguous subsequences which recursively add up to 9 | Set 2 | C # program to count substrings with recursive sum equal to 9 ; to store no . of previous encountered modular sums ; no . of modular sum ( == 0 ) encountered till now = 1 ; if number is 0 increase ; no . of continuous_zero by 1 ; else continuous_zero is 0 ; increase d value of this mod_sum ; subtract no . of cases where there are only zeroes in substring ; driver program to test above function
using System ; class GFG { static int count9s ( string number ) { int n = number . Length ; int [ ] d = new int [ 9 ] ; d [ 0 ] = 1 ; int result = 0 ; int mod_sum = 0 , continuous_zero = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( number [ i ] - '0' ) == 0 ) { continuous_zero ++ ; } else { continuous_zero = 0 ; } mod_sum += ( number [ i ] - '0' ) ; mod_sum %= 9 ; result += d [ mod_sum ] ; d [ mod_sum ] ++ ; result -= continuous_zero ; } return result ; } public static void Main ( ) { Console . WriteLine ( count9s ( "01809" ) ) ; Console . WriteLine ( count9s ( "1809" ) ) ; Console . WriteLine ( count9s ( "4189" ) ) ; } }
Extract maximum numeric value from a given string | Set 1 ( General approach ) | C # program for above implementation ; Utility method to find maximum string ; If both having equal lengths ; Reach first unmatched character / value ; Return string with maximum value ; If different lengths return string with maximum length ; Method to extract the maximum value ; Start traversing the string ; Ignore leading zeroes ; Store numeric value into a string ; Update maximum string ; To handle the case if there is only 0 numeric value ; Return maximum string ; Driver method
using System ; class GFG { static String maximumNum ( string curr_num , string res ) { int len1 = curr_num . Length ; int len2 = res . Length ; if ( len1 == len2 ) { int i = 0 ; while ( curr_num [ i ] == res [ i ] ) i ++ ; if ( curr_num [ i ] < res [ i ] ) return res ; else return curr_num ; } return len1 < len2 ? res : curr_num ; } static string extractMaximum ( string str ) { int n = str . Length ; string curr_num = " " ; string res = " " ; for ( int i = 0 ; i < n ; i ++ ) { while ( i < n && str [ i ] == '0' ) i ++ ; while ( i < n && Char . IsDigit ( str [ i ] ) ) { curr_num = curr_num + str [ i ] ; i ++ ; } if ( i == n ) break ; if ( curr_num . Length > 0 ) i -- ; res = maximumNum ( curr_num , res ) ; curr_num = " " ; } if ( curr_num . Length == 0 && res . Length == 0 ) res = res + '0' ; return maximumNum ( curr_num , res ) ; } public static void Main ( ) { string str = "100klh564abc365bg " ; Console . WriteLine ( extractMaximum ( str ) ) ; } }
To check divisibility of any large number by 999 | C # code for divisibility of number by 999 ; Method to check divisibility ; Append required 0 s at the beginning . ; add digits in group of three in gSum ; group saves 3 - digit group ; calculate result till 3 digit sum ; Driver method
using System ; class Test { static bool isDivisible999 ( String num ) { int n = num . Length ; if ( n == 0 && num [ 0 ] == '0' ) return true ; if ( n % 3 == 1 ) num = "00" + num ; if ( n % 3 == 2 ) num = "0" + num ; int gSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int group = 0 ; group += ( num [ i ++ ] - '0' ) * 100 ; group += ( num [ i ++ ] - '0' ) * 10 ; group += num [ i ] - '0' ; gSum += group ; } if ( gSum > 1000 ) { num = Convert . ToString ( gSum ) ; n = num . Length ; gSum = isDivisible999 ( num ) ? 1 : 0 ; } return ( gSum == 999 ) ; } public static void Main ( ) { String num = "1998" ; Console . WriteLine ( isDivisible999 ( num ) ? " Divisible " : " Not ▁ divisible " ) ; } }
Rearrange a string in sorted order followed by the integer sum | C # program for above implementation ; Method to return string in lexicographic order followed by integers sum ; Traverse the string ; Count occurrence of uppercase alphabets ; Store sum of integers ; Traverse for all characters A to Z ; Append the current character in the string no . of times it occurs in the given string ; Append the sum of integers ; return resultant string ; Driver method
using System ; class GFG { static int MAX_CHAR = 26 ; static String arrangeString ( string str ) { int [ ] char_count = new int [ MAX_CHAR ] ; int sum = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( char . IsUpper ( str [ i ] ) ) char_count [ str [ i ] - ' A ' ] ++ ; else sum = sum + ( str [ i ] - '0' ) ; } string res = " " ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { char ch = ( char ) ( ' A ' + i ) ; while ( char_count [ i ] -- != 0 ) res = res + ch ; } if ( sum > 0 ) res = res + sum ; return res ; } public static void Main ( ) { string str = " ACCBA10D2EW30" ; Console . Write ( arrangeString ( str ) ) ; } }
URLify a given string ( Replace spaces is % 20 ) | C # implementation of above approach ; Instantiate the string ; Trim the given string ; Replace All space ( unicode is \\ s ) to % 20 ; Display the result
using System ; class GFG { public static void Main ( ) { String str = " Mr ▁ John ▁ Smith ▁ " ; str = str . Trim ( ) ; str = str . Replace ( " ▁ " , " % 20" ) ; Console . Write ( str ) ; } }
Program to print all substrings of a given string | C # program to print all possible substrings of a given string ; Function to print all sub strings ; Pick starting point ; Pick ending point ; Print characters from current starting point to current ending point . ; Driver program to test above function
using System ; public class GFG { static void subString ( string str , int n ) { for ( int len = 1 ; len <= n ; len ++ ) { for ( int i = 0 ; i <= n - len ; i ++ ) { int j = i + len - 1 ; for ( int k = i ; k <= j ; k ++ ) Console . Write ( str [ k ] ) ; Console . WriteLine ( ) ; } } } static public void Main ( ) { string str = " abc " ; subString ( str , str . Length ) ; } }
Reverse a string preserving space positions | C # program to reverse a string preserving spaces . ; Function to reverse the string and preserve the space position ; Mark spaces in result ; Traverse input string from beginning and put characters in result from end ; Ignore spaces in input string ; ignore spaces in result . ; Driver code
using System ; class GFG { static void reverses ( string str ) { char [ ] inputArray = str . ToCharArray ( ) ; char [ ] result = new char [ inputArray . Length ] ; for ( int i = 0 ; i < inputArray . Length ; i ++ ) { if ( inputArray [ i ] == ' ▁ ' ) { result [ i ] = ' ▁ ' ; } } int j = result . Length - 1 ; for ( int i = 0 ; i < inputArray . Length ; i ++ ) { if ( inputArray [ i ] != ' ▁ ' ) { if ( result [ j ] == ' ▁ ' ) { j -- ; } result [ j ] = inputArray [ i ] ; j -- ; } } for ( int i = 0 ; i < result . Length ; i ++ ) Console . Write ( result [ i ] ) ; } public static void Main ( ) { reverses ( " internship ▁ at ▁ geeks ▁ for ▁ geeks " ) ; } }
Find uncommon characters of the two strings | C # implementation to find the uncommon characters of the two strings ; size of the hash table ; function to find the uncommon characters of the two strings ; mark presence of each character as 0 in the hash table ' present [ ] ' ; for each character of str1 , mark its presence as 1 in ' present [ ] ' ; for each character of str2 ; if a character of str2 is also present in str1 , then mark its presence as - 1 ; else mark its presence as 2 ; print all the uncommon characters ; Driver code
using System ; class GFG { static int MAX_CHAR = 26 ; static void findAndPrintUncommonChars ( String str1 , String str2 ) { int [ ] present = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { present [ i ] = 0 ; } int l1 = str1 . Length ; int l2 = str2 . Length ; for ( int i = 0 ; i < l1 ; i ++ ) { present [ str1 [ i ] - ' a ' ] = 1 ; } for ( int i = 0 ; i < l2 ; i ++ ) { if ( present [ str2 [ i ] - ' a ' ] == 1 present [ str2 [ i ] - ' a ' ] == - 1 ) { present [ str2 [ i ] - ' a ' ] = - 1 ; } else { present [ str2 [ i ] - ' a ' ] = 2 ; } } for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { if ( present [ i ] == 1 present [ i ] == 2 ) { Console . Write ( ( char ) ( i + ' a ' ) + " ▁ " ) ; } } } public static void Main ( String [ ] args ) { String str1 = " characters " ; String str2 = " alphabets " ; findAndPrintUncommonChars ( str1 , str2 ) ; } }
Length Of Last Word in a String | C # program for implementation of simple approach to find length of last word ; String a is ' final ' -- can not be modified So , create a copy and trim the spaces from both sides ; Driver code
using System ; class GFG { public virtual int lengthOfLastWord ( string a ) { int len = 0 ; string x = a . Trim ( ) ; for ( int i = 0 ; i < x . Length ; i ++ ) { if ( x [ i ] == ' ▁ ' ) { len = 0 ; } else { len ++ ; } } return len ; } public static void Main ( string [ ] args ) { string input = " Geeks ▁ For ▁ Geeks ▁ " ; GFG gfg = new GFG ( ) ; Console . WriteLine ( " The ▁ length ▁ of ▁ last ▁ word ▁ is ▁ " + gfg . lengthOfLastWord ( input ) ) ; } }
Program to count vowels in a string ( Iterative and Recursive ) | C # program to count vowels in a string ; Function to check the Vowel ; Returns count of vowels in str ; Check for vowel ; Driver code ; string object ; Total numbers of Vowel
using System ; class GFG { public static bool isVowel ( char ch ) { ch = char . ToUpper ( ch ) ; return ( ch == ' A ' ch == ' E ' ch == ' I ' ch == ' O ' ch == ' U ' ) ; } public static int countVowels ( string str ) { int count = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( isVowel ( str [ i ] ) ) { ++ count ; } } return count ; } public static void Main ( string [ ] args ) { string str = " abc ▁ de " ; Console . WriteLine ( countVowels ( str ) ) ; } }
Toggle case of a string using Bitwise Operators | C # program to get toggle case of a string ; tOGGLE cASE = swaps CAPS to lower case and lower case to CAPS ; Bitwise EXOR with 32 ; Driver program
using System ; class GFG { static string toggleCase ( char [ ] a ) { for ( int i = 0 ; i < a . Length ; i ++ ) { a [ i ] ^= ( char ) 32 ; } return new string ( a ) ; } public static void Main ( ) { string str = " CheRrY " ; Console . Write ( " Toggle ▁ case : ▁ " ) ; str = toggleCase ( str . ToCharArray ( ) ) ; Console . WriteLine ( str ) ; Console . Write ( " Original ▁ string : ▁ " ) ; str = toggleCase ( str . ToCharArray ( ) ) ; Console . Write ( str ) ; } }
Determine if a string has all Unique Characters | C # program to illustrate String with unique characters using set data structure ; Inserting character of String into set ; If length of set is equal to len of String then it will have unique characters ; Driver code
using System ; using System . Collections . Generic ; public class GFG { static bool uniquechars ( String str ) { HashSet < char > char_set = new HashSet < char > ( ) ; for ( int c = 0 ; c < str . Length ; c ++ ) { char_set . Add ( str ) ; } if ( char_set . Count == str . Length ) { return true ; } else { return false ; } } public static void Main ( String [ ] args ) { String str = " GeeksforGeeks " ; if ( uniquechars ( str ) ) { Console . Write ( " The ▁ String ▁ " + str + " ▁ has ▁ all ▁ unique ▁ characters STRNEWLINE " ) ; } else { Console . Write ( " The ▁ String ▁ " + str + " ▁ has ▁ duplicate ▁ characters STRNEWLINE " ) ; } } }
Ropes Data Structure ( Fast String Concatenation ) | C # program to concatenate two strings ; Function that concatenates strings a [ 0. . n1 - 1 ] and b [ 0. . n2 - 1 ] and stores the result in c [ ] ; Copy characters of A [ ] to C [ ] ; Copy characters of B [ ] ; Driver code ; Concatenate a [ ] and b [ ] and store result in c [ ]
using System ; public class GFG { static void concatenate ( char [ ] a , char [ ] b , char [ ] c , int n1 , int n2 ) { int i ; for ( i = 0 ; i < n1 ; i ++ ) { c [ i ] = a [ i ] ; } for ( int j = 0 ; j < n2 ; j ++ ) { c [ i ++ ] = b [ j ] ; } } public static void Main ( ) { char [ ] a = " Hi ▁ This ▁ is ▁ geeksforgeeks . ▁ " . ToCharArray ( ) ; int n1 = a . Length ; char [ ] b = " You ▁ are ▁ welcome ▁ here . " . ToCharArray ( ) ; int n2 = b . Length ; char [ ] c = new char [ n1 + n2 ] ; concatenate ( a , b , c , n1 , n2 ) ; for ( int i = 0 ; i < n1 + n2 - 1 ; i ++ ) { Console . Write ( c [ i ] ) ; } } }
Convert characters of a string to opposite case | C # program to toggle all characters ; Function to toggle characters ; Driver code
using System ; class GFG { static char [ ] S = " GeKf @ rGeek $ " . ToCharArray ( ) ; static void toggleChars ( ) { for ( int i = 0 ; i < S . Length ; i ++ ) { if ( char . IsLetter ( S [ i ] ) ) { S [ i ] = ( char ) ( ( int ) ( S [ i ] ) ^ ( 1 << 5 ) ) ; } } } public static void Main ( String [ ] args ) { toggleChars ( ) ; Console . Write ( " String ▁ after ▁ toggle ▁ " + " STRNEWLINE " ) ; Console . Write ( String . Join ( " " , S ) ) ; } }
Binary representation of next greater number with same number of 1 ' s ▁ and ▁ 0' s | C # program to find next permutation in a binary string . ; Function to find the next greater number with same number of 1 ' s ▁ and ▁ 0' s ; locate first ' i ' from end such that bnum [ i ] == '0' and bnum [ i + 1 ] == '1' swap these value and break ; ; if no swapping performed ; Since we want the smallest next value , shift all 1 ' s ▁ at ▁ the ▁ end ▁ in ▁ the ▁ binary ▁ ▁ substring ▁ starting ▁ from ▁ index ▁ ' i + 2 ' ; special case while swapping if '0' occurs then break ; required next greater number ; Driver code
using System ; class GFG { static String nextGreaterWithSameDigits ( char [ ] bnum ) { int l = bnum . Length ; int i ; for ( i = l - 2 ; i >= 1 ; i -- ) { if ( bnum [ i ] == '0' && bnum [ i + 1 ] == '1' ) { char ch = bnum [ i ] ; bnum [ i ] = bnum [ i + 1 ] ; bnum [ i + 1 ] = ch ; break ; } } if ( i == 0 ) Console . WriteLine ( " no ▁ greater ▁ number " ) ; int j = i + 2 , k = l - 1 ; while ( j < k ) { if ( bnum [ j ] == '1' && bnum [ k ] == '0' ) { char ch = bnum [ j ] ; bnum [ j ] = bnum [ k ] ; bnum [ k ] = ch ; j ++ ; k -- ; } else if ( bnum [ i ] == '0' ) break ; else j ++ ; } return String . Join ( " " , bnum ) ; } public static void Main ( String [ ] args ) { char [ ] bnum = "10010" . ToCharArray ( ) ; Console . WriteLine ( " Binary ▁ representation ▁ of ▁ next ▁ greater ▁ number ▁ = ▁ " + nextGreaterWithSameDigits ( bnum ) ) ; } }
Generate all rotations of a given string | A simple C # program to generate all rotations of a given string ; Print all the rotated string . ; Generate all rotations one by one and print ; Current index in str ; Current index in temp ; Copying the second part from the point of rotation . ; Copying the first part from the point of rotation . ; Driver Code
using System ; using System . Text ; class GFG { public static void printRotatedString ( string str ) { int len = str . Length ; StringBuilder sb ; for ( int i = 0 ; i < len ; i ++ ) { sb = new StringBuilder ( ) ; int j = i ; int k = 0 ; for ( int k2 = j ; k2 < str . Length ; k2 ++ ) { sb . Insert ( k , str [ j ] ) ; k ++ ; j ++ ; } j = 0 ; while ( j < i ) { sb . Insert ( k , str [ j ] ) ; j ++ ; k ++ ; } Console . WriteLine ( sb ) ; } } public static void Main ( string [ ] args ) { string str = " geeks " ; printRotatedString ( str ) ; } }
Longest Non | C # implementation to find maximum length substring which is not palindrome ; utility function to check whether a string is palindrome or not ; Check for palindrome . ; palindrome string ; function to find maximum length substring which is not palindrome ; to check whether all characters of the string are same or not ; All characters are same , we can 't  make a non-palindromic string. ; If string is palindrome , we can make it non - palindrome by removing any corner character ; Complete string is not a palindrome . ; Driver code
using System ; class GFG { static bool isPalindrome ( String str ) { int n = str . Length ; for ( int i = 0 ; i < n / 2 ; i ++ ) if ( str [ i ] != str [ n - i - 1 ] ) return false ; return true ; } static int maxLengthNonPalinSubstring ( String str ) { int n = str . Length ; char ch = str [ 0 ] ; int i = 1 ; for ( i = 1 ; i < n ; i ++ ) if ( str [ i ] != ch ) break ; if ( i == n ) return 0 ; if ( isPalindrome ( str ) ) return n - 1 ; return n ; } public static void Main ( ) { String str = " abba " ; Console . Write ( " Maximum ▁ Length ▁ = ▁ " + maxLengthNonPalinSubstring ( str ) ) ; } }