codeparrot/xlcost-text-to-code huggingface dataset:
Print characters and their frequencies in order of occurrence using Binary Tree | Java implementation of the above approach ; Node in the tree where data holds the character of the String and cnt holds the frequency ; Function to add a new node to the Binary Tree ; Create a new node and populate its data part , set cnt as 1 and left and right children as null ; Function to add a node to the Binary Tree in level order ; Use the queue data structure for level order insertion and push the root of tree to Queue ; If the character to be inserted is present , update the cnt ; If the left child is empty add a new node as the left child ; If the character is present as a left child , update the cnt and exit the loop ; Add the left child to the queue for further processing ; If the right child is empty , add a new node to the right ; If the character is present as a right child , update the cnt and exit the loop ; Add the right child to the queue for further processing ; Function to print the level order traversal of the Binary Tree ; Add the root to the queue ; If the cnt of the character is more then one , display cnt ; If the cnt of character is one , display character only ; Add the left child to the queue for further processing ; Add the right child to the queue for further processing ; Driver code ; Add individual characters to the String one by one in level order ; Print the level order of the constructed binary tree
import java . util . * ; class GFG { static class node { char data ; int cnt ; node left , right ; } ; static node add ( char data ) { node newnode = new node ( ) ; newnode . data = data ; newnode . cnt = 1 ; newnode . left = newnode . right = null ; return newnode ; } static node addinlvlorder ( node root , char data ) { if ( root == null ) { return add ( data ) ; } Queue < node > Q = new LinkedList < node > ( ) ; Q . add ( root ) ; while ( ! Q . isEmpty ( ) ) { node temp = Q . peek ( ) ; Q . remove ( ) ; if ( temp . data == data ) { temp . cnt ++ ; break ; } if ( temp . left == null ) { temp . left = add ( data ) ; break ; } else { if ( temp . left . data == data ) { temp . left . cnt ++ ; break ; } Q . add ( temp . left ) ; } if ( temp . right == null ) { temp . right = add ( data ) ; break ; } else { if ( temp . right . data == data ) { temp . right . cnt ++ ; break ; } Q . add ( temp . right ) ; } } return root ; } static void printlvlorder ( node root ) { Queue < node > Q = new LinkedList < node > ( ) ; Q . add ( root ) ; while ( ! Q . isEmpty ( ) ) { node temp = Q . peek ( ) ; if ( temp . cnt > 1 ) { System . out . print ( ( temp . data + " " + temp . cnt ) ) ; } else { System . out . print ( ( char ) temp . data ) ; } Q . remove ( ) ; if ( temp . left != null ) { Q . add ( temp . left ) ; } if ( temp . right != null ) { Q . add ( temp . right ) ; } } } public static void main ( String [ ] args ) { String s = " geeksforgeeks " ; node root = null ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { root = addinlvlorder ( root , s . charAt ( i ) ) ; } printlvlorder ( root ) ; } }
Find the resultant String after replacing X with Y and removing Z | Java program to find the resultant String after replacing X with Y and removing Z ; Function to replace and remove ; Two pointer start and end points to beginning and end position in the string ; If start is having Z find X pos in end and replace Z with another character ; Find location for having different character instead of Z ; If found swap character at start and end ; Else increment start Also checkin for X at start position ; Driver code
class GFG { static String replaceRemove ( char [ ] s , char X , char Y , char Z ) { int start = 0 , end = s . length - 1 ; while ( start <= end ) { if ( s [ start ] == Z ) { while ( end >= 0 && s [ end ] == Z ) { end -- ; } char temp ; if ( end > start ) { temp = s [ start ] ; s [ start ] = s [ end ] ; s [ end ] = temp ; if ( s [ start ] == X ) s [ start ] = Y ; start ++ ; } } else { if ( s [ start ] == X ) s [ start ] = Y ; start ++ ; } } String new_s = new String ( s ) ; while ( new_s . length ( ) > 0 && new_s . charAt ( new_s . length ( ) - 1 ) == Z ) { new_s = new_s . substring ( 0 , new_s . length ( ) - 1 ) ; } return new_s ; } public static void main ( String [ ] args ) { String str = " batman " ; char X = ' a ' , Y = ' d ' , Z = ' b ' ; str = replaceRemove ( str . toCharArray ( ) , X , Y , Z ) ; if ( str . length ( ) == 0 ) { System . out . println ( - 1 ) ; } else { System . out . println ( str ) ; } } }
Check if all bits can be made same by flipping two consecutive bits | Java program for the above approach ; Function to check if Binary string can be made equal ; Counting occurence of zero and one in binary string ; From above observation ; Driver code
class GFG { static String canMake ( String s ) { int o = 0 , z = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) - '0' == 1 ) o ++ ; else z ++ ; } if ( o % 2 == 1 && z % 2 == 1 ) return " NO " ; else return " YES " ; } public static void main ( String [ ] args ) { String s = "01011" ; System . out . println ( canMake ( s ) ) ; } }
Count of non | Java implementation of the above approach ; Function to find the count of the number of strings ; Loop to iterate over the frequency of character of string ; reduce the frequency of current element ; recursive call ; freq [ i ] ++ ; backtrack ; Function to count the number of non - empty sequences ; store the frequency of each character ; Maintain the frequency ; Driver Code ; Function Call
import java . io . * ; import java . util . * ; class GFG { public static int count = 0 ; public static void countNumberOfStringsUtil ( int [ ] freq ) { for ( int i = 0 ; i < 26 ; i ++ ) { if ( freq [ i ] > 0 ) { freq [ i ] -- ; count ++ ; countNumberOfStringsUtil ( freq ) ; } } } public static int countNumberOfStrings ( String s ) { int [ ] freq = new int [ 26 ] ; Arrays . fill ( freq , 0 ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { freq [ s . charAt ( i ) - ' A ' ] ++ ; } countNumberOfStringsUtil ( freq ) ; return count ; } public static void main ( String [ ] args ) { String s = " AAABBC " ; System . out . println ( countNumberOfStrings ( s ) ) ; } }
Minimum swaps required to make a binary string divisible by 2 ^ k | Java implementation of the approach ; Function to return the minimum swaps required ; To store the final answer ; To store the count of one and zero ; Loop from end of the string ; If s [ i ] = 1 ; If s [ i ] = 0 ; If c_zero = k ; If the result can 't  be achieved ; Return the final answer ; Driver code
class GFG { static int findMinSwaps ( String s , int k ) { int ans = 0 ; int c_one = 0 , c_zero = 0 ; for ( int i = s . length ( ) - 1 ; i >= 0 ; i -- ) { if ( s . charAt ( i ) == '1' ) c_one ++ ; if ( s . charAt ( i ) == '0' ) { c_zero ++ ; ans += c_one ; } if ( c_zero == k ) break ; } if ( c_zero < k ) return - 1 ; return ans ; } public static void main ( String [ ] args ) { String s = "100111" ; int k = 2 ; System . out . println ( findMinSwaps ( s , k ) ) ; } }
Remove vowels from a string stored in a Binary Tree | Java program for the above approach ; Structure Representing the Node in the Binary tree ; Function to perform a level order insertion of a new Node in the Binary tree ; If the root is empty , make it point to the new Node ; In case there are elements in the Binary tree , perform a level order traversal using a Queue ; If the left child does not exist , insert the new Node as the left child ; In case the right child does not exist , insert the new Node as the right child ; Function to print the level order traversal of the Binary tree ; Function to check if the character is a vowel or not . ; Function to remove the vowels in the new Binary tree ; Declaring the root of the new tree ; If the given character is not a vowel , add it to the new Binary tree ; Driver code
import java . util . * ; class GFG { static class Node { char data ; Node left , right ; Node ( char _val ) { data = _val ; left = right = null ; } } ; static Node addinBT ( Node root , char data ) { if ( root == null ) { root = new Node ( data ) ; } else { Queue < Node > Q = new LinkedList < Node > ( ) ; Q . add ( root ) ; while ( ! Q . isEmpty ( ) ) { Node temp = Q . peek ( ) ; Q . remove ( ) ; if ( temp . left == null ) { temp . left = new Node ( data ) ; break ; } else Q . add ( temp . left ) ; if ( temp . right == null ) { temp . right = new Node ( data ) ; break ; } else Q . add ( temp . right ) ; } } return root ; } static void print ( Node root ) { Queue < Node > Q = new LinkedList < Node > ( ) ; Q . add ( root ) ; while ( Q . size ( ) > 0 ) { Node temp = Q . peek ( ) ; Q . remove ( ) ; System . out . print ( temp . data ) ; if ( temp . left != null ) Q . add ( temp . left ) ; if ( temp . right != null ) Q . add ( temp . right ) ; } } static boolean checkvowel ( char ch ) { ch = Character . toLowerCase ( ch ) ; if ( ch == ' a ' ch == ' e ' ch == ' i ' ch == ' o ' ch == ' u ' ) { return true ; } else { return false ; } } static Node removevowels ( Node root ) { Queue < Node > Q = new LinkedList < Node > ( ) ; Q . add ( root ) ; Node root1 = null ; while ( ! Q . isEmpty ( ) ) { Node temp = Q . peek ( ) ; Q . remove ( ) ; if ( ! checkvowel ( temp . data ) ) { root1 = addinBT ( root1 , temp . data ) ; } if ( temp . left != null ) { Q . add ( temp . left ) ; } if ( temp . right != null ) { Q . add ( temp . right ) ; } } return root1 ; } public static void main ( String [ ] args ) { String s = " geeks " ; Node root = null ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { root = addinBT ( root , s . charAt ( i ) ) ; } root = removevowels ( root ) ; print ( root ) ; } }
Number of sub | Java implementation of the approach ; Function to return the count of the required substrings ; To store the final answer ; Loop to find the answer ; Condition to update the answer ; Driver code
class GFG { static int countSubStr ( String str , int len ) { int ans = 0 ; for ( int i = 0 ; i < len ; i ++ ) { if ( str . charAt ( i ) == '0' ) ans += ( i + 1 ) ; } return ans ; } public static void main ( String [ ] args ) { String str = "10010" ; int len = str . length ( ) ; System . out . println ( countSubStr ( str , len ) ) ; } }
Smallest non | Java implementation of the approach ; Function to return the length of the smallest substring divisible by 2 ^ k ; To store the final answer ; Left pointer ; Right pointer ; Count of the number of zeros and ones in the current substring ; Loop for two pointers ; Condition satisfied ; Updated the answer ; Update the pointer and count ; Update the pointer and count ; Driver code
class GFG { static final int INT_MAX = Integer . MAX_VALUE ; static int findLength ( String s , int k ) { int ans = INT_MAX ; int l = 0 ; int r = 0 ; int cnt_zero = 0 , cnt_one = 0 ; while ( l < s . length ( ) && r <= s . length ( ) ) { if ( cnt_zero >= k && cnt_one >= 1 ) { ans = Math . min ( ans , r - l ) ; l ++ ; if ( s . charAt ( l - 1 ) == '0' ) cnt_zero -- ; else cnt_one -- ; } else { if ( r == s . length ( ) ) break ; if ( s . charAt ( r ) == '0' ) cnt_zero ++ ; else cnt_one ++ ; r ++ ; } } if ( ans == INT_MAX ) return - 1 ; return ans ; } public static void main ( String [ ] args ) { String s = "100" ; int k = 2 ; System . out . println ( findLength ( s , k ) ) ; } }
Largest sub | Java implementation of the approach ; Function to return the largest substring divisible by 2 ; While the last character of the string is '1' , pop it ; If the original string had no '0' ; Driver code
class GFG { static String largestSubStr ( String s ) { while ( s . length ( ) != 0 && s . charAt ( s . length ( ) - 1 ) == '1' ) s = s . substring ( 0 , s . length ( ) - 1 ) ; if ( s . length ( ) == 0 ) return " - 1" ; else return s ; } public static void main ( String [ ] args ) { String s = "11001" ; System . out . println ( largestSubStr ( s ) ) ; } }
Find whether X exists in Y after jumbling X | Java implementation of the approach ; Function that returns true if both the arrays have equal values ; Test the equality ; Function that returns true if any permutation of X exists as a subString in Y ; Base case ; To store cumulative frequency ; Finding the frequency of characters in X ; Finding the frequency of characters in Y upto the length of X ; Equality check ; Two pointer approach to generate the entire cumulative frequency ; Remove the first character of the previous window ; Add the last character of the current window ; Equality check ; Driver code
class GFG { static int MAX = 26 ; static boolean areEqual ( int [ ] a , int [ ] b ) { for ( int i = 0 ; i < MAX ; i ++ ) if ( a [ i ] != b [ i ] ) return false ; return true ; } static boolean xExistsInY ( String x , String y ) { if ( x . length ( ) > y . length ( ) ) return false ; int [ ] cnt_x = new int [ MAX ] ; int [ ] cnt = new int [ MAX ] ; for ( int i = 0 ; i < x . length ( ) ; i ++ ) cnt_x [ x . charAt ( i ) - ' a ' ] ++ ; for ( int i = 0 ; i < x . length ( ) ; i ++ ) cnt [ y . charAt ( i ) - ' a ' ] ++ ; if ( areEqual ( cnt_x , cnt ) ) return true ; for ( int i = 1 ; i < y . length ( ) - x . length ( ) + 1 ; i ++ ) { cnt [ y . charAt ( i - 1 ) - ' a ' ] -- ; cnt [ y . charAt ( i + x . length ( ) - 1 ) - ' a ' ] ++ ; if ( areEqual ( cnt , cnt_x ) ) return true ; } return false ; } public static void main ( String [ ] args ) { String x = " skege " ; String y = " geeksforgeeks " ; if ( xExistsInY ( x , y ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }
Reverse substrings between each pair of parenthesis | Java implementation of the approach ; Function to return the modified string ; Push the index of the current opening bracket ; Reverse the substring starting after the last encountered opening bracket till the current character ; To store the modified string ; Driver code
import java . io . * ; import java . util . * ; class GFG { static void reverse ( char A [ ] , int l , int h ) { if ( l < h ) { char ch = A [ l ] ; A [ l ] = A [ h ] ; A [ h ] = ch ; reverse ( A , l + 1 , h - 1 ) ; } } static String reverseParentheses ( String str , int len ) { Stack < Integer > st = new Stack < Integer > ( ) ; for ( int i = 0 ; i < len ; i ++ ) { if ( str . charAt ( i ) == ' ( ' ) { st . push ( i ) ; } else if ( str . charAt ( i ) == ' ) ' ) { char [ ] A = str . toCharArray ( ) ; reverse ( A , st . peek ( ) + 1 , i ) ; str = String . copyValueOf ( A ) ; st . pop ( ) ; } } String res = " " ; for ( int i = 0 ; i < len ; i ++ ) { if ( str . charAt ( i ) != ' ) ' && str . charAt ( i ) != ' ( ' ) { res += ( str . charAt ( i ) ) ; } } return res ; } public static void main ( String [ ] args ) { String str = " ( skeeg ( for ) skeeg ) " ; int len = str . length ( ) ; System . out . println ( reverseParentheses ( str , len ) ) ; } }
Count of times second string can be formed from the characters of first string | Java implementation of the approach ; Function to update the freq [ ] array to store the frequencies of all the characters of str ; Update the frequency of the characters ; Function to return the maximum count of times patt can be formed using the characters of str ; To store the frequencies of all the characters of str ; To store the frequencies of all the characters of patt ; To store the result ; For every character ; If the current character doesn 't appear in patt ; Update the result ; Driver code
class GFG { static int MAX = 26 ; static void updateFreq ( String str , int freq [ ] ) { int len = str . length ( ) ; for ( int i = 0 ; i < len ; i ++ ) { freq [ str . charAt ( i ) - ' a ' ] ++ ; } } static int maxCount ( String str , String patt ) { int [ ] strFreq = new int [ MAX ] ; updateFreq ( str , strFreq ) ; int [ ] pattFreq = new int [ MAX ] ; updateFreq ( patt , pattFreq ) ; int ans = Integer . MAX_VALUE ; for ( int i = 0 ; i < MAX ; i ++ ) { if ( pattFreq [ i ] == 0 ) continue ; ans = Math . min ( ans , strFreq [ i ] / pattFreq [ i ] ) ; } return ans ; } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; String patt = " geeks " ; System . out . print ( maxCount ( str , patt ) ) ; } }
Reduce the number to minimum multiple of 4 after removing the digits | Java implementation of the approach ; Function to return the minimum number that can be formed after removing the digits which is a multiple of 4 ; For every digit of the number ; Check if the current digit is divisible by 4 ; If any subsequence of two digits is divisible by 4 ; Driver code
class GFG { static int TEN = 10 ; static int minNum ( char [ ] str , int len ) { int res = Integer . MAX_VALUE ; for ( int i = 0 ; i < len ; i ++ ) { if ( str [ i ] == '4' str [ i ] == '8' ) { res = Math . min ( res , str [ i ] - '0' ) ; } } for ( int i = 0 ; i < len - 1 ; i ++ ) { for ( int j = i + 1 ; j < len ; j ++ ) { int num = ( str [ i ] - '0' ) * TEN + ( str [ j ] - '0' ) ; if ( num % 4 == 0 ) { res = Math . min ( res , num ) ; } } } return ( ( res == Integer . MAX_VALUE ) ? - 1 : res ) ; } public static void main ( String [ ] args ) { String str = "17" ; int len = str . length ( ) ; System . out . print ( minNum ( str . toCharArray ( ) , len ) ) ; } }
Check if two strings can be made equal by swapping one character among each other | Java implementation of the approach ; Function that returns true if the string can be made equal after one swap ; A and B are new a and b after we omit the same elements ; Take only the characters which are different in both the strings for every pair of indices ; If the current characters differ ; The strings were already equal ; If the lengths of the strings are two ; If swapping these characters can make the strings equal ; Driver code
import java . util . * ; class GFG { static boolean canBeEqual ( char [ ] a , char [ ] b , int n ) { Vector < Character > A = new Vector < > ( ) ; Vector < Character > B = new Vector < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] != b [ i ] ) { A . add ( a [ i ] ) ; B . add ( b [ i ] ) ; } } if ( A . size ( ) == B . size ( ) && B . size ( ) == 0 ) return true ; if ( A . size ( ) == B . size ( ) && B . size ( ) == 2 ) { if ( A . get ( 0 ) == A . get ( 1 ) && B . get ( 0 ) == B . get ( 1 ) ) return true ; } return false ; } public static void main ( String [ ] args ) { char [ ] A = " SEEKSFORGEEKS " . toCharArray ( ) ; char [ ] B = " GEEKSFORGEEKG " . toCharArray ( ) ; if ( canBeEqual ( A , B , A . length ) ) System . out . printf ( " Yes " ) ; else System . out . printf ( " No " ) ; } }
Find the Mid | Java program to find the Mid - Alphabet for each index of the given Pair of Strings ; Function to find the mid alphabets ; For every character pair ; Get the average of the characters ; Driver code
class GFG { static void findMidAlphabet ( String s1 , String s2 , int n ) { for ( int i = 0 ; i < n ; i ++ ) { int mid = ( s1 . charAt ( i ) + s2 . charAt ( i ) ) / 2 ; System . out . print ( ( char ) mid ) ; } } public static void main ( String [ ] args ) { String s1 = " akzbqzgw " ; String s2 = " efhctcsz " ; int n = s1 . length ( ) ; findMidAlphabet ( s1 , s2 , n ) ; } }
Queries to find the count of vowels in the substrings of the given string | Java implementation of the approach ; Function that returns true if ch is a vowel ; pre [ i ] will store the count of vowels in the subString str [ 0. . . i ] ; Fill the pre [ ] array ; If current character is a vowel ; If its a consonant ; For every query ; Find the count of vowels for the current query ; Driver code
class GFG { static final int N = 2 ; static Boolean isVowel ( char ch ) { return ( ch == ' a ' ch == ' e ' ch == ' i ' ch == ' o ' ch == ' u ' ) ; } static void performQueries ( String str , int len , int queries [ ] [ ] , int q ) { int [ ] pre = new int [ len ] ; if ( isVowel ( str . charAt ( 0 ) ) ) pre [ 0 ] = 1 ; else pre [ 0 ] = 0 ; for ( int i = 1 ; i < len ; i ++ ) { if ( isVowel ( str . charAt ( i ) ) ) pre [ i ] = 1 + pre [ i - 1 ] ; else pre [ i ] = pre [ i - 1 ] ; } for ( int i = 0 ; i < q ; i ++ ) { if ( queries [ i ] [ 0 ] == 0 ) { System . out . println ( pre [ queries [ i ] [ 1 ] ] ) ; } else { System . out . println ( ( pre [ queries [ i ] [ 1 ] ] - pre [ queries [ i ] [ 0 ] - 1 ] ) ) ; } } } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; int len = str . length ( ) ; int queries [ ] [ ] = { { 1 , 3 } , { 2 , 4 } , { 1 , 9 } } ; int q = queries . length ; performQueries ( str , len , queries , q ) ; } }
Check whether the given decoded string is divisible by 6 | Java implementation of the approach ; Function to return the sum of the digits of n ; Function that return true if the decoded string is divisible by 6 ; To store the sum of the digits ; For each character , get the sum of the digits ; If the sum of digits is not divisible by 3 ; Get the last digit of the number formed ; If the last digit is not divisible by 2 ; Driver code
class GFG { static int sumDigits ( int n ) { int sum = 0 ; while ( n > 0 ) { int digit = n % 10 ; sum += digit ; n /= 10 ; } return sum ; } static boolean isDivBySix ( String str , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += ( int ) ( str . charAt ( i ) - ' a ' + 1 ) ; } if ( sum % 3 != 0 ) return false ; int lastDigit = ( ( int ) ( str . charAt ( n - 1 ) - ' a ' + 1 ) ) % 10 ; if ( lastDigit % 2 != 0 ) return false ; return true ; } public static void main ( String [ ] args ) { String str = " ab " ; int n = str . length ( ) ; if ( isDivBySix ( str , n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Check the divisibility of Hexadecimal numbers | Java implementation of the approach ; Function that returns true if s is divisible by m ; Map to map characters to real values ; To store the remainder at any stage ; Find the remainder ; Check the value of remainder ; Driver code
import java . util . * ; class GFG { static char [ ] CHARS = "0123456789ABCDEF " . toCharArray ( ) ; static int DIGITS = 16 ; static boolean isDivisible ( String s , int m ) { Map < Character , Integer > mp = new HashMap < > ( ) ; for ( int i = 0 ; i < DIGITS ; i ++ ) { mp . put ( CHARS [ i ] , i ) ; } int r = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { r = ( r * 16 + mp . get ( s . charAt ( i ) ) ) % m ; } if ( r == 0 ) return true ; return false ; } public static void main ( String [ ] args ) { String s = "10" ; int m = 3 ; if ( isDivisible ( s , m ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Maximum number of splits of a binary number | Java implementation of the approach ; Function to return the required count ; If the splitting is not possible ; To store the final ans ; Counting the number of zeros ; Return the final answer ; Driver code
class GFG { static int cntSplits ( String s ) { if ( s . charAt ( s . length ( ) - 1 ) == '1' ) return - 1 ; int ans = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) ans += ( s . charAt ( i ) == '0' ) ? 1 : 0 ; return ans ; } public static void main ( String [ ] args ) { String s = "10010" ; System . out . println ( cntSplits ( s ) ) ; } }
Modify the string such that every character gets replaced with the next character in the keyboard | Java implementation of the approach ; Function to return the modified String ; Map to store the next character on the keyboard for every possible lowercase character ; Update the String ; Driver code
import java . util . * ; class GFG { static String CHARS = " qwertyuiopasdfghjklzxcvbnm " ; static int MAX = 26 ; static String getString ( char [ ] str , int n ) { Map < Character , Character > uMap = new HashMap < > ( ) ; for ( int i = 0 ; i < MAX ; i ++ ) { uMap . put ( CHARS . charAt ( i ) , CHARS . charAt ( ( i + 1 ) % MAX ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { str [ i ] = uMap . get ( str [ i ] ) ; } return String . valueOf ( str ) ; } public static void main ( String [ ] args ) { String str = " geeks " ; int n = str . length ( ) ; System . out . println ( getString ( str . toCharArray ( ) , n ) ) ; } }