codeparrot/xlcost-text-to-code huggingface dataset:
Move spaces to front of string in single traversal | C # program to bring all spaces in front of string using swapping technique ; Function to find spaces and move to beginning ; Traverse from end and swap spaces ; Driver code
using System ; class GFG { static void moveSpaceInFront ( char [ ] str ) { int i = str . Length - 1 ; for ( int j = i ; j >= 0 ; j -- ) if ( str [ j ] != ' ▁ ' ) { char c = str [ i ] ; str [ i ] = str [ j ] ; str [ j ] = c ; i -- ; } } public static void Main ( ) { char [ ] str = " Hey ▁ there , ▁ it ' s ▁ GeeksforGeeks " . ToCharArray ( ) ; moveSpaceInFront ( str ) ; Console . WriteLine ( String . Join ( " " , str ) ) ; } }
Move spaces to front of string in single traversal | C # program to bring all spaces in front of string using swapping technique ; Function to find spaces and move to beginning ; Keep copying non - space characters ; Move spaces to be beginning ; Driver code
using System ; class GFG { static void moveSpaceInFront ( char [ ] str ) { int i = str . Length - 1 ; for ( int j = i ; j >= 0 ; j -- ) if ( str [ j ] != ' ▁ ' ) str [ i -- ] = str [ j ] ; while ( i >= 0 ) str [ i -- ] = ' ▁ ' ; } public static void Main ( String [ ] args ) { char [ ] str = " Hey ▁ there , ▁ it ' s ▁ GeeksforGeeks " . ToCharArray ( ) ; moveSpaceInFront ( str ) ; Console . WriteLine ( String . Join ( " " , str ) ) ; } }
Minimum number of Appends needed to make a string palindrome | C # program to find minimum number of appends needed to make a string Palindrome ; Checking if the string is palindrome or not ; single character is always palindrome ; pointing to first character ; pointing to last character ; Recursive function to count number of appends ; Removing first character of string by incrementing base address pointer . ; Driver code
using System ; class GFG { static Boolean isPalindrome ( char [ ] str ) { int len = str . Length ; if ( len == 1 ) return true ; char ptr1 = str [ 0 ] ; char ptr2 = str [ len - 1 ] ; while ( ptr2 > ptr1 ) { if ( ptr1 != ptr2 ) return false ; ptr1 ++ ; ptr2 -- ; } return true ; } static int noOfAppends ( String s ) { if ( isPalindrome ( s . ToCharArray ( ) ) ) return 0 ; s = s . Substring ( 1 ) ; return 1 + noOfAppends ( s ) ; } public static void Main ( String [ ] arr ) { String s = " abede " ; Console . Write ( " { 0 } STRNEWLINE " , noOfAppends ( s ) ) ; } }
Find Excel column number from column title | C # program to return title to result of excel sheet . ; Returns resul when we pass title . ; This process is similar to binary - to - decimal conversion ; Driver Code
using System ; class GFG { public static int titleToNumber ( string s ) { int result = 0 ; for ( int i = 0 ; i < s . Length ; i ++ ) { result *= 26 ; result += s [ i ] - ' A ' + 1 ; } return result ; } public static void Main ( string [ ] args ) { Console . Write ( titleToNumber ( " CDA " ) ) ; } }
Check whether K | C # program to check if k - th bit of a given number is set or not using right shift operator ; Driver code
using System ; class GFG { static void isKthBitSet ( int n , int k ) { if ( ( ( n >> ( k - 1 ) ) & 1 ) > 0 ) Console . WriteLine ( " SET " ) ; else Console . WriteLine ( " NOT ▁ SET " ) ; } static public void Main ( ) { int n = 5 , k = 1 ; isKthBitSet ( n , k ) ; } }
Reverse string without using any temporary variable | C # Program to reverse a string without using temp variable ; Function to reverse string and return revesed string ; Iterate loop upto start not equal to end ; XOR for swapping the variable ; Driver Code
using System ; class GFG { static String reversingString ( char [ ] str , int start , int end ) { while ( start < end ) { str [ start ] ^= str [ end ] ; str [ end ] ^= str [ start ] ; str [ start ] ^= str [ end ] ; ++ start ; -- end ; } return String . Join ( " " , str ) ; } public static void Main ( String [ ] args ) { String s = " GeeksforGeeks " ; Console . WriteLine ( reversingString ( s . ToCharArray ( ) , 0 , 12 ) ) ; } }
Check if a string follows a ^ nb ^ n pattern or not | C # code to check a ^ nb ^ n pattern ; Returns " Yes " str is of the form a ^ nb ^ n . ; check first half is ' a ' and other half is full of ' b ' ; Driver code ; Function call
using System ; public class GFG { static string isAnBn ( string str ) { int n = str . Length ; if ( ( n & 1 ) != 0 ) return " No " ; int i ; for ( i = 0 ; i < n / 2 ; i ++ ) if ( str [ i ] != ' a ' str [ n - i - 1 ] != ' b ' ) return " No " ; return " Yes " ; } static public void Main ( ) { string str = " ab " ; Console . WriteLine ( isAnBn ( str ) ) ; } }
Number of substrings divisible by 6 in a string of integers | C # program to calculate number of substring divisible by 6. ; Return the number of substring divisible by 6 and starting at index i in s [ ] and previous sum of digits modulo 3 is m . ; End of the string . ; If already calculated , return the stored value . ; Converting into integer . ; Increment result by 1 , if current digit is divisible by 2 and sum of digits is divisible by 3. And recur for next index with new modulo . ; Returns substrings divisible by 6. ; For storing the value of all states . ; If string contain 0 , increment count by 1. ; Else calculate using recursive function . Pass previous sum modulo 3 as 0. ; Driver code
using System ; class GFG { static int MAX = 100002 ; static int f ( int i , int m , char [ ] s , int [ , ] memoize ) { if ( i == s . Length ) { return 0 ; } if ( memoize [ i , m ] != - 1 ) { return memoize [ i , m ] ; } int x = s [ i ] - '0' ; int ans = ( ( ( ( x + m ) % 3 == 0 ) && ( x % 2 == 0 ) ) ? 1 : 0 ) + f ( i + 1 , ( m + x ) % 3 , s , memoize ) ; return memoize [ i , m ] = ans ; } static int countDivBy6 ( char [ ] s ) { int n = s . Length ; int [ , ] memoize = new int [ n + 1 , 3 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { memoize [ i , j ] = - 1 ; } } int ans = 0 ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( s [ i ] == '0' ) { ans ++ ; } else { ans += f ( i , 0 , s , memoize ) ; } } return ans ; } public static void Main ( String [ ] args ) { char [ ] s = "4806" . ToCharArray ( ) ; Console . WriteLine ( countDivBy6 ( s ) ) ; } }
Lexicographically first palindromic string | C # program to find first palindromic permutation of given string ; Function to count frequency of each char in the string . freq [ 0 ] for ' a ' , ... . , freq [ 25 ] for ' z ' ; Cases to check whether a palindr0mic string can be formed or not ; count_odd to count no of chars with odd frequency ; For even length string no odd freq character ; For odd length string one odd freq character ; Function to find odd freq char and reducing its freq by 1 returns " " if odd freq char is not present ; To find lexicographically first palindromic string . ; Assigning odd freq character if present else empty string . ; Traverse characters in increasing order ; Divide all occurrences into two halves . Note that odd character is removed by findOddAndRemoveItsFreq ( ) ; creating front string ; creating rear string ; Final palindromic string which is lexicographically first ; Driver code
using System ; class GFG { static int MAX_CHAR = 26 ; static void countFreq ( string str , int [ ] freq , int len ) { for ( int i = 0 ; i < len ; i ++ ) { freq [ str [ i ] - ' a ' ] ++ ; } } static bool canMakePalindrome ( int [ ] freq , int len ) { int count_odd = 0 ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { if ( freq [ i ] % 2 != 0 ) { count_odd ++ ; } } if ( len % 2 == 0 ) { if ( count_odd > 0 ) { return false ; } else { return true ; } } if ( count_odd != 1 ) { return false ; } return true ; } static string findOddAndRemoveItsFreq ( int [ ] freq ) { string odd_str = " " ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { if ( freq [ i ] % 2 != 0 ) { freq [ i ] -- ; odd_str = odd_str + ( char ) ( i + ' a ' ) ; return odd_str ; } } return odd_str ; } static string findPalindromicString ( string str ) { int len = str . Length ; int [ ] freq = new int [ MAX_CHAR ] ; countFreq ( str , freq , len ) ; if ( ! canMakePalindrome ( freq , len ) ) { return " No ▁ Palindromic ▁ String " ; } string odd_str = findOddAndRemoveItsFreq ( freq ) ; string front_str = " " , rear_str = " ▁ " ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { String temp = " " ; if ( freq [ i ] != 0 ) { char ch = ( char ) ( i + ' a ' ) ; for ( int j = 1 ; j <= freq [ i ] / 2 ; j ++ ) { temp = temp + ch ; } front_str = front_str + temp ; rear_str = temp + rear_str ; } } return ( front_str + odd_str + rear_str ) ; } public static void Main ( ) { string str = " malayalam " ; Console . Write ( findPalindromicString ( str ) ) ; } }
Count substrings with same first and last characters | C # program to count all substrings with same first and last characters . ; Returns true if first and last characters of s are same . ; Starting point of substring ; Length of substring ; Check if current substring has same starting and ending characters . ; Driver code
using System ; class GFG { static bool checkEquality ( string s ) { return ( s [ 0 ] == s [ s . Length - 1 ] ) ; } static int countSubstringWithEqualEnds ( string s ) { int result = 0 ; int n = s . Length ; for ( int i = 0 ; i < n ; i ++ ) for ( int len = 1 ; len <= n - i ; len ++ ) if ( checkEquality ( s . Substring ( i , len ) ) ) result ++ ; return result ; } public static void Main ( ) { string s = " abcab " ; Console . WriteLine ( countSubstringWithEqualEnds ( s ) ) ; } }
Count substrings with same first and last characters | Space efficient C # program to count all substrings with same first and last characters . ; Iterating through all substrings in way so that we can find first and last character easily ; Driver function
using System ; public class GFG { static int countSubstringWithEqualEnds ( string s ) { int result = 0 ; int n = s . Length ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i ; j < n ; j ++ ) if ( s [ i ] == s [ j ] ) result ++ ; return result ; } public static void Main ( ) { string s = " abcab " ; Console . Write ( countSubstringWithEqualEnds ( s ) ) ; } }
Find the missing number in a string of numbers with no separator | C # program to find a missing number in a string of consecutive numbers without any separator . ; gets the integer at position i with length m , returns it or - 1 , if none ; Find value at index i and length m . ; Returns value of missing number ; Try all lengths for first number ; Get value of first number with current length / ; To store missing number of current length ; To indicate whether the sequence failed anywhere for current length . ; Find subsequent numbers with previous number as n ; If we haven 't yet found the missing number  for current length. Next number is n+2. Note  that we use Log10 as (n+2) may have more  length than n. ; } If next value is ( n + 1 ) ; return - 1 ; not found or no missing number ; Driver code
using System ; public class GFG { static readonly int MAX_DIGITS = 6 ; static int getValue ( String str , int i , int m ) { if ( i + m > str . Length ) { return - 1 ; } int value = 0 ; for ( int j = 0 ; j < m ; j ++ ) { int c = str [ i + j ] - '0' ; if ( c < 0 c > 9 ) { return - 1 ; } value = value * 10 + c ; } return value ; } static int findMissingNumber ( String str ) { for ( int m = 1 ; m <= MAX_DIGITS ; ++ m ) { int n = getValue ( str , 0 , m ) ; if ( n == - 1 ) { break ; } int missingNo = - 1 ; bool fail = false ; for ( int i = m ; i != str . Length ; i += 1 + ( int ) Math . Log10 ( n ) ) { if ( ( missingNo == - 1 ) && ( getValue ( str , i , ( int ) ( 1 + Math . Log10 ( n + 2 ) ) ) == n + 2 ) ) { missingNo = n + 1 ; n += 2 ; else if ( getValue ( str , i , ( int ) ( 1 + Math . Log10 ( n + 1 ) ) ) == n + 1 ) { n ++ ; } else { fail = true ; break ; } } if ( ! fail ) { return missingNo ; } } } public static void Main ( ) { Console . WriteLine ( findMissingNumber ( "99101102" ) ) ; } }
Maximum consecutive repeating character in string | C # program to find the maximum consecutive repeating character in given string ; function to find out the maximum repeating character in given string ; Find the maximum repeating character starting from str [ i ] ; Update result if required ; Driver code
using System ; class GFG { static char maxRepeating ( string str ) { int len = str . Length ; int count = 0 ; char res = str [ 0 ] ; for ( int i = 0 ; i < len ; i ++ ) { int cur_count = 1 ; for ( int j = i + 1 ; j < len ; j ++ ) { if ( str [ i ] != str [ j ] ) break ; cur_count ++ ; } if ( cur_count > count ) { count = cur_count ; res = str [ i ] ; } } return res ; } public static void Main ( ) { string str = " aaaabbaaccde " ; Console . Write ( maxRepeating ( str ) ) ; } }
Sum of two large numbers | C # program to find sum of two large numbers . ; Function for finding sum of larger numbers ; Before proceeding further , make sure length of str2 is larger . ; Take an empty string for storing result ; Calculate length of both string ; Reverse both of strings ; Do school mathematics , compute sum of current digits and carry ; Calculate carry for next step ; Add remaining digits of larger number ; Add remaining carry ; reverse resultant string ; Driver code
using System ; class GFG { static string findSum ( string str1 , string str2 ) { if ( str1 . Length > str2 . Length ) { string t = str1 ; str1 = str2 ; str2 = t ; } string str = " " ; int n1 = str1 . Length , n2 = str2 . Length ; char [ ] ch = str1 . ToCharArray ( ) ; Array . Reverse ( ch ) ; str1 = new string ( ch ) ; char [ ] ch1 = str2 . ToCharArray ( ) ; Array . Reverse ( ch1 ) ; str2 = new string ( ch1 ) ; int carry = 0 ; for ( int i = 0 ; i < n1 ; i ++ ) { int sum = ( ( int ) ( str1 [ i ] - '0' ) + ( int ) ( str2 [ i ] - '0' ) + carry ) ; str += ( char ) ( sum % 10 + '0' ) ; carry = sum / 10 ; } for ( int i = n1 ; i < n2 ; i ++ ) { int sum = ( ( int ) ( str2 [ i ] - '0' ) + carry ) ; str += ( char ) ( sum % 10 + '0' ) ; carry = sum / 10 ; } if ( carry > 0 ) str += ( char ) ( carry + '0' ) ; char [ ] ch2 = str . ToCharArray ( ) ; Array . Reverse ( ch2 ) ; str = new string ( ch2 ) ; return str ; } static void Main ( ) { string str1 = "12" ; string str2 = "198111" ; Console . WriteLine ( findSum ( str1 , str2 ) ) ; } }
Sum of two large numbers | C # program to find sum of two large numbers . ; Function for finding sum of larger numbers ; Before proceeding further , make sure length of str2 is larger . ; Take an empty string for storing result ; Calculate length of both string ; Initially take carry zero ; Traverse from end of both strings ; Do school mathematics , compute sum of current digits and carry ; Add remaining digits of str2 [ ] ; Add remaining carry ; reverse resultant string ; Driver code
using System ; class GFG { static string findSum ( string str1 , string str2 ) { if ( str1 . Length > str2 . Length ) { string t = str1 ; str1 = str2 ; str2 = t ; } string str = " " ; int n1 = str1 . Length , n2 = str2 . Length ; int diff = n2 - n1 ; int carry = 0 ; for ( int i = n1 - 1 ; i >= 0 ; i -- ) { int sum = ( ( int ) ( str1 [ i ] - '0' ) + ( int ) ( str2 [ i + diff ] - '0' ) + carry ) ; str += ( char ) ( sum % 10 + '0' ) ; carry = sum / 10 ; } for ( int i = n2 - n1 - 1 ; i >= 0 ; i -- ) { int sum = ( ( int ) ( str2 [ i ] - '0' ) + carry ) ; str += ( char ) ( sum % 10 + '0' ) ; carry = sum / 10 ; } if ( carry > 0 ) str += ( char ) ( carry + '0' ) ; char [ ] ch2 = str . ToCharArray ( ) ; Array . Reverse ( ch2 ) ; return new string ( ch2 ) ; } static void Main ( ) { string str1 = "12" ; string str2 = "198111" ; Console . WriteLine ( findSum ( str1 , str2 ) ) ; } }
Palindrome pair in an array of words ( or strings ) | C # program to find if there is a pair that can form a palindrome . ; Utility function to check if a string is a palindrome ; compare each character from starting with its corresponding character from last ; Function to check if a palindrome pair exists ; Consider each pair one by one ; concatenate both strings ; check if the concatenated string is palindrome ; check if the concatenated string is palindrome ; Driver code
using System ; using System . Collections . Generic ; class GFG { static Boolean isPalindrome ( String str ) { int len = str . Length ; for ( int i = 0 ; i < len / 2 ; i ++ ) if ( str [ i ] != str [ len - i - 1 ] ) return false ; return true ; } static Boolean checkPalindromePair ( List < String > vect ) { for ( int i = 0 ; i < vect . Count - 1 ; i ++ ) { for ( int j = i + 1 ; j < vect . Count ; j ++ ) { String check_str = " " ; check_str = check_str + vect [ i ] + vect [ j ] ; if ( isPalindrome ( check_str ) ) return true ; check_str = vect [ j ] + vect [ j ] ; if ( isPalindrome ( check_str ) ) return true ; } } return false ; } public static void Main ( String [ ] args ) { List < String > vect = new List < String > ( ) { " geekf " , " geeks " , " or " , " keeg " , " abc " , " bc " } ; if ( checkPalindromePair ( vect ) == true ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Print consecutive characters together in a line | C # program to print consecutive characters together in a line . ; Driver code
using System ; class GFG { static void print ( String str1 ) { char [ ] str = str1 . ToCharArray ( ) ; Console . Write ( str [ 0 ] ) ; for ( int i = 1 ; i < str . Length ; i ++ ) { if ( ( str [ i ] == str [ i - 1 ] + 1 ) || ( str [ i ] == str [ i - 1 ] - 1 ) ) { Console . Write ( str [ i ] ) ; } else { Console . Write ( " STRNEWLINE " + str [ i ] ) ; } } } public static void Main ( ) { String str = " ABCXYZACCD " ; print ( str ) ; } }
Efficiently check if a string has all unique characters without using any additional data structure | A space efficient program to check if all characters of string are unique . ; Returns true if all characters of str are unique . Assumptions : ( 1 ) str contains only characters from ' a ' to ' z ' . ( 2 ) integers are stored using 32 bits ; An integer to store presence or absence of 26 characters using its 32 bits . ; If bit corresponding to current character is already set ; set bit in checker ; Driver code
using System ; class GFG { static bool areChractersUnique ( string str ) { int checker = 0 ; for ( int i = 0 ; i < str . Length ; ++ i ) { int val = ( str [ i ] - ' a ' ) ; if ( ( checker & ( 1 << val ) ) > 0 ) return false ; checker |= ( 1 << val ) ; } return true ; } public static void Main ( ) { string s = " aaabbccdaa " ; if ( areChractersUnique ( s ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Count of words whose i | C # program to count words whose ith letter is either ( i - 1 ) th , ith , or ( i + 1 ) th letter of the given word ; Return the count of words . ; If word contain single letter , return 1. ; Checking for first letter . ; Traversing the string and multiplying for combinations . ; If all three letters are same . ; If two letter are distinct . ; If all three letter are distinct . ; Checking for last letter . ; Driver Program
using System ; public class GFG { static int countWords ( string str , int len ) { int count = 1 ; if ( len == 1 ) return count ; if ( str [ 0 ] == str [ 1 ] ) count *= 1 ; else count *= 2 ; for ( int j = 1 ; j < len - 1 ; j ++ ) { if ( str [ j ] == str [ j - 1 ] && str [ j ] == str [ j + 1 ] ) count *= 1 ; else if ( str [ j ] == str [ j - 1 ] str [ j ] == str [ j + 1 ] str [ j - 1 ] == str [ j + 1 ] ) count *= 2 ; else count *= 3 ; } if ( str [ len - 1 ] == str [ len - 2 ] ) count *= 1 ; else count *= 2 ; return count ; } public static void Main ( ) { string str = " abc " ; int len = str . Length ; Console . WriteLine ( countWords ( str , len ) ) ; } }
Maximum and minimum sums from two numbers with digit replacements | C # program to find maximum and minimum possible sums of two numbers that we can get if replacing digit from 5 to 6 and vice versa are allowed . ; Find new value of x after replacing digit " from " to " to " ; Required digit found , replace it ; Returns maximum and minimum possible sums of x1 and x2 if digit replacements are allowed . ; We always get minimum sum if we replace 6 with 5. ; We always get maximum sum if we replace 5 with 6. ; Driver code
using System ; class GFG { static int replaceDig ( int x , int from , int to ) { int result = 0 ; int multiply = 1 ; while ( x > 0 ) { int reminder = x % 10 ; if ( reminder == from ) result = result + to * multiply ; else result = result + reminder * multiply ; multiply *= 10 ; x = x / 10 ; } return result ; } static void calculateMinMaxSum ( int x1 , int x2 ) { int minSum = replaceDig ( x1 , 6 , 5 ) + replaceDig ( x2 , 6 , 5 ) ; int maxSum = replaceDig ( x1 , 5 , 6 ) + replaceDig ( x2 , 5 , 6 ) ; Console . Write ( " Minimum ▁ sum ▁ = ▁ " + minSum ) ; Console . Write ( " STRNEWLINE Maximum ▁ sum ▁ = ▁ " + maxSum ) ; } public static void Main ( ) { int x1 = 5466 , x2 = 4555 ; calculateMinMaxSum ( x1 , x2 ) ; } }
Queries on substring palindrome formation | C # program to Queries on substring palindrome formation . ; Query type 1 : update string position i with character x . ; Print " Yes " if range [ L . . R ] can form palindrome , else print " No " . ; Find the frequency of each character in S [ L ... R ] . ; Checking if more than one character have frequency greater than 1. ; Driver code
using System ; class GFG { static void qType1 ( int l , int x , char [ ] str ) { str [ l - 1 ] = ( char ) x ; } static void qType2 ( int l , int r , char [ ] str ) { int [ ] freq = new int [ 27 ] ; for ( int i = l - 1 ; i <= r - 1 ; i ++ ) { freq [ str [ i ] - ' a ' ] ++ ; } int count = 0 ; for ( int j = 0 ; j < 26 ; j ++ ) { if ( freq [ j ] % 2 != 0 ) { count ++ ; } } if ( count <= 1 ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } public static void Main ( String [ ] args ) { char [ ] str = " geeksforgeeks " . ToCharArray ( ) ; int n = str . Length ; qType1 ( 4 , ' g ' , str ) ; qType2 ( 1 , 4 , str ) ; qType2 ( 2 , 3 , str ) ; qType1 ( 10 , ' t ' , str ) ; qType2 ( 10 , 11 , str ) ; } }
Queries on substring palindrome formation | C # program to Queries on substring palindrome formation . ; Return the frequency of the character in the i - th prefix . ; Updating the BIT ; Query to update the character in the string . ; Adding - 1 at L position ; Updating the character ; Adding + 1 at R position ; Query to find if rearrangement of character in range L ... R can form palindrome ; Checking on the first character of the string S . ; Checking if frequency of character is even or odd . ; Creating the Binary Index Tree of all aphabet ; Driver code
using System ; class GFG { static int max = 1000 ; static int getFrequency ( int [ , ] tree , int idx , int i ) { int sum = 0 ; while ( idx > 0 ) { sum += tree [ idx , i ] ; idx -= ( idx & - idx ) ; } return sum ; } static void update ( int [ , ] tree , int idx , int val , int i ) { while ( idx <= max ) { tree [ idx , i ] += val ; idx += ( idx & - idx ) ; } } static void qType1 ( int [ , ] tree , int l , int x , char [ ] str ) { update ( tree , l , - 1 , str [ l - 1 ] - 97 + 1 ) ; str [ l - 1 ] = ( char ) x ; update ( tree , l , 1 , str [ l - 1 ] - 97 + 1 ) ; } static void qType2 ( int [ , ] tree , int l , int r , char [ ] str ) { int count = 0 ; for ( int i = 1 ; i <= 26 ; i ++ ) { if ( l == 1 ) { if ( getFrequency ( tree , r , i ) % 2 == 1 ) count ++ ; } else { if ( ( getFrequency ( tree , r , i ) - getFrequency ( tree , l - 1 , i ) ) % 2 == 1 ) count ++ ; } } if ( count <= 1 ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } static void buildBIT ( int [ , ] tree , char [ ] str , int n ) { for ( int i = 0 ; i < n ; i ++ ) update ( tree , i + 1 , 1 , str [ i ] - 97 + 1 ) ; } static void Main ( ) { char [ ] str = " geeksforgeeks " . ToCharArray ( ) ; int n = str . Length ; int [ , ] tree = new int [ max , 27 ] ; buildBIT ( tree , str , n ) ; qType1 ( tree , 4 , ' g ' , str ) ; qType2 ( tree , 1 , 4 , str ) ; qType2 ( tree , 2 , 3 , str ) ; qType1 ( tree , 10 , ' t ' , str ) ; qType2 ( tree , 10 , 11 , str ) ; } }