codeparrot/xlcost-text-to-code huggingface dataset:
Convert to a string that is repetition of a substring of k length | Java program to check if a string can be converted to a string that has repeated substrings of length k . ; Returns true if str can be converted to a string with k repeated substrings after replacing k characters . ; Length of string must be a multiple of k ; Map to store strings of length k and their counts ; If string is already a repetition of k substrings , return true . ; If number of distinct substrings is not 2 , then not possible to replace a string . ; One of the two distinct must appear exactly once . Either the first entry appears once , or it appears n / k - 1 times to make other substring appear once . ; Driver code
import java . util . HashMap ; import java . util . Iterator ; class GFG { static boolean checkString ( String str , int k ) { int n = str . length ( ) ; if ( n % k != 0 ) return false ; HashMap < String , Integer > mp = new HashMap < > ( ) ; try { for ( int i = 0 ; i < n ; i += k ) mp . put ( str . substring ( i , k ) , mp . get ( str . substring ( i , k ) ) == null ? 1 : mp . get ( str . substring ( i , k ) ) + 1 ) ; } catch ( Exception e ) { } if ( mp . size ( ) == 1 ) return true ; if ( mp . size ( ) != 2 ) return false ; HashMap . Entry < String , Integer > entry = mp . entrySet ( ) . iterator ( ) . next ( ) ; if ( entry . getValue ( ) == ( n / k - 1 ) || entry . getValue ( ) == 1 ) return true ; return false ; } public static void main ( String [ ] args ) { if ( checkString ( " abababcd " , 2 ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Group all occurrences of characters according to first appearance | Java program to print all occurrences of every character together . ; Since only lower case characters are there ; Method to print the string ; Initialize counts of all characters as 0 ; Count occurrences of all characters in string ; Starts traversing the string ; Print the character till its count in hash array ; Make this character 's count value as 0. ; Driver method
class Test { static final int MAX_CHAR = 26 ; static void printGrouped ( String str ) { int n = str . length ( ) ; int count [ ] = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < n ; i ++ ) count [ str . charAt ( i ) - ' a ' ] ++ ; for ( int i = 0 ; i < n ; i ++ ) { while ( count [ str . charAt ( i ) - ' a ' ] != 0 ) { System . out . print ( str . charAt ( i ) ) ; count [ str . charAt ( i ) - ' a ' ] -- ; } count [ str . charAt ( i ) - ' a ' ] = 0 ; } } public static void main ( String args [ ] ) { String str = new String ( " geeksforgeeks " ) ; printGrouped ( str ) ; } }
Sort a string according to the order defined by another string | Java program to sort a string according to the order defined by a pattern string ; Sort str according to the order defined by pattern . ; Create a count array stor count of characters in str . ; Count number of occurrences of each character in str . ; Traverse the pattern and print every characters same number of times as it appears in str . This loop takes O ( m + n ) time where m is length of pattern and n is length of str . ; Driver code
class GFG { static int MAX_CHAR = 26 ; static void sortByPattern ( char [ ] str , char [ ] pat ) { int count [ ] = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < str . length ; i ++ ) { count [ str [ i ] - ' a ' ] ++ ; } int index = 0 ; for ( int i = 0 ; i < pat . length ; i ++ ) { for ( int j = 0 ; j < count [ pat [ i ] - ' a ' ] ; j ++ ) { str [ index ++ ] = pat [ i ] ; } } } public static void main ( String args [ ] ) { char [ ] pat = " bca " . toCharArray ( ) ; char [ ] str = " abc " . toCharArray ( ) ; sortByPattern ( str , pat ) ; System . out . println ( String . valueOf ( str ) ) ; } }
Smallest Palindrome after replacement | Java program to get lexicographically smallest palindrome string ; Utility method to check str is possible palindrome after ignoring ; If both left and right character are not dot and they are not equal also , then it is not possible to make this string a palindrome ; Returns lexicographically smallest palindrome string , if possible ; loop through character of string ; if one of character is dot , replace dot with other character ; if both character are dot , then replace them with smallest character ' a ' ; return the result ; Driver code
class GFG { static boolean isPossiblePalindrome ( char str [ ] ) { int n = str . length ; for ( int i = 0 ; i < n / 2 ; i ++ ) { if ( str [ i ] != ' . ' && str [ n - i - 1 ] != ' . ' && str [ i ] != str [ n - i - 1 ] ) return false ; } return true ; } static void smallestPalindrome ( char str [ ] ) { if ( ! isPossiblePalindrome ( str ) ) System . out . println ( " Not ▁ Possible " ) ; int n = str . length ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' . ' ) { if ( str [ n - i - 1 ] != ' . ' ) str [ i ] = str [ n - i - 1 ] ; else str [ i ] = str [ n - i - 1 ] = ' a ' ; } } for ( int i = 0 ; i < n ; i ++ ) System . out . print ( str [ i ] + " " ) ; } public static void main ( String [ ] args ) { String str = " ab . . e . c . a " ; char [ ] s = str . toCharArray ( ) ; smallestPalindrome ( s ) ; } }
Number of flips to make binary string alternate | Set 1 | Java program to find minimum number of flip to make binary string alternate ; Utility method to flip a character ; Utility method to get minimum flips when alternate string starts with expected char ; if current character is not expected , increase flip count ; flip expected character each time ; method return minimum flip to make binary string alternate ; return minimum of following two 1 ) flips when alternate string starts with 0 2 ) flips when alternate string starts with 1 ; Driver code to test above method
class GFG { public static char flip ( char ch ) { return ( ch == '0' ) ? '1' : '0' ; } public static int getFlipWithStartingCharcter ( String str , char expected ) { int flipCount = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) != expected ) flipCount ++ ; expected = flip ( expected ) ; } return flipCount ; } public static int minFlipToMakeStringAlternate ( String str ) { return Math . min ( getFlipWithStartingCharcter ( str , '0' ) , getFlipWithStartingCharcter ( str , '1' ) ) ; } public static void main ( String args [ ] ) { String str = "0001010111" ; System . out . println ( minFlipToMakeStringAlternate ( str ) ) ; } }
Remainder with 7 for large numbers | Java program to find remainder of a large number when divided by 7. ; Function which return Remainder after dividingthe number by 7 ; This series is used to find remainder with 7 ; Index of next element in series ; Initialize result ; Traverse num from end ; Find current digit of nun ; Add next term to result ; Move to next term in series ; Make sure that result never goes beyond 7. ; Make sure that remainder is positive ; Driver code
class GFG { static int remainderWith7 ( String num ) { int series [ ] = { 1 , 3 , 2 , - 1 , - 3 , - 2 } ; int series_index = 0 ; int result = 0 ; for ( int i = num . length ( ) - 1 ; i >= 0 ; i -- ) { int digit = num . charAt ( i ) - '0' ; result += digit * series [ series_index ] ; series_index = ( series_index + 1 ) % 6 ; result %= 7 ; } if ( result < 0 ) result = ( result + 7 ) % 7 ; return result ; } public static void main ( String [ ] args ) { String str = "12345" ; System . out . print ( " Remainder ▁ with ▁ 7 ▁ is ▁ " + remainderWith7 ( str ) ) ; } }
Check if a string can become empty by recursively deleting a given sub | Java program to check if a string can be converted to an empty string by deleting given sub - string from any position , any number of times . ; Returns true if str can be made empty by recursively removing sub_str . ; idx : to store starting index of sub - string found in the original string ; Erasing the found sub - string from the original string ; Driver code
class GFG { static boolean canBecomeEmpty ( String str , String sub_str ) { while ( str . length ( ) > 0 ) { int idx = str . indexOf ( sub_str ) ; if ( idx == - 1 ) { break ; } str = str . replaceFirst ( sub_str , " " ) ; } return ( str . length ( ) == 0 ) ; } public static void main ( String [ ] args ) { String str = " GEEGEEKSKS " , sub_str = " GEEKS " ; if ( canBecomeEmpty ( str , sub_str ) ) { System . out . print ( " Yes "); } else { System . out . print ( " No "); } } }
Perfect reversible string | Java program to check if a string is perfect reversible or nor ; This function basically checks if string is palindrome or not ; iterate from left and right ; Driver Code
import java . io . * ; class GFG { static boolean isReversible ( String str ) { int i = 0 , j = str . length ( ) - 1 ; while ( i < j ) { if ( str . charAt ( i ) != str . charAt ( j ) ) return false ; i ++ ; j -- ; } return true ; } public static void main ( String [ ] args ) { String str = " aba " ; if ( isReversible ( str ) ) System . out . print ( " YES " ) ; else System . out . print ( " NO " ) ; } }
Check if string follows order of characters defined by a pattern or not | Set 3 | Java program to find if a string follows order defined by a given pattern . ; Returns true if characters of str follow order defined by a given ptr . ; Initialize all orders as - 1 ; Assign an order to pattern characters according to their appearance in pattern ; give the pattern characters order ; increment the order ; Now one by check if string characters follow above order ; If order of this character is less than order of previous , return false . ; Update last_order for next iteration ; return that str followed pat ; Driver code
class GFG { static int CHAR_SIZE = 256 ; static boolean checkPattern ( String str , String pat ) { int [ ] label = new int [ CHAR_SIZE ] ; for ( int i = 0 ; i < CHAR_SIZE ; i ++ ) label [ i ] = - 1 ; int order = 1 ; for ( int i = 0 ; i < pat . length ( ) ; i ++ ) { label [ pat . charAt ( i ) ] = order ; order ++ ; } int last_order = - 1 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( label [ str . charAt ( i ) ] != - 1 ) { if ( label [ str . charAt ( i ) ] < last_order ) return false ; last_order = label [ str . charAt ( i ) ] ; } } return true ; } public static void main ( String [ ] args ) { String str = " engineers ▁ rock " ; String pattern = " gsr " ; System . out . println ( checkPattern ( str , pattern ) ) ; } }
Check if string follows order of characters defined by a pattern or not | Set 2 | Java program to check if characters of a string follow pattern defined by given pattern . ; Insert all characters of pattern in a hash set , ; Build modified string ( string with characters only from pattern are taken ) ; Remove more than one consecutive occurrences of pattern characters from modified string . ; After above modifications , the length of modified string must be same as pattern length ; And pattern characters must also be same as modified string characters ; Driver program
import java . util . * ; public class OrderOfCharactersForPattern { public static boolean followsPattern ( String str , String pattern ) { Set < Character > patternSet = neHashSet < > ( ) ; for ( int i = 0 ; i < pattern . length ( ) ; i ++ ) patternSet . add ( pattern . charAt ( i ) ) ; StringBuilder modifiedString = new StringBuilder ( str ) ; for ( int i = str . length ( ) - 1 ; i >= 0 ; i -- ) if ( ! patternSet . contains ( modifiedString . charAt ( i ) ) ) modifiedString . deleteCharAt ( i ) ; for ( int i = modifiedString . length ( ) - 1 ; i > 0 ; i -- ) if ( modifiedString . charAt ( i ) == modifiedString . charAt ( i - 1 ) ) modifiedString . deleteCharAt ( i ) ; if ( pattern . length ( ) != modifiedString . length ( ) ) return false ; for ( int i = 0 ; i < pattern . length ( ) ; i ++ ) if ( pattern . charAt ( i ) != modifiedString . charAt ( i ) ) return false ; return true ; } int main ( ) { String str = " engineers ▁ rock " ; String pattern = " er " ; System . out . println ( " Expected : ▁ true , ▁ Actual : ▁ " + followsPattern ( str , pattern ) ) ; str = " engineers ▁ rock " ; pattern = " egr " ; System . out . println ( " Expected : ▁ false , ▁ Actual : ▁ " + followsPattern ( str , pattern ) ) ; str = " engineers ▁ rock " ; pattern = " gsr " ; System . out . println ( " Expected : ▁ false , ▁ Actual : ▁ " + followsPattern ( str , pattern ) ) ; str = " engineers ▁ rock " ; pattern = " eger " ; System . out . println ( " Expected : ▁ true , ▁ Actual : ▁ " + followsPattern ( str , pattern ) ) ; return 0 ; } }
Find k 'th character of decrypted string | Set 1 | Java program to find K 'th character in decrypted string ; Function to find K 'th character in  Encoded String ; expand string variable is used to store final string after decompressing string str ; String temp = " " ; Current substring int freq = 0 ; Count of current substring ; read characters until you find a number or end of string ; push character in temp ; read number for how many times string temp will be repeated in decompressed string ; generating frequency of temp ; now append string temp into expand equal to its frequency ; this condition is to handle the case when string str is ended with alphabets not with numeric value ; Driver program to test the string
public class GFG { static char encodedChar ( String str , int k ) { String expand = " " ; for ( int i = 0 ; i < str . length ( ) ; ) { while ( i < str . length ( ) && str . charAt ( i ) >= ' a ' && str . charAt ( i ) <= ' z ' ) { temp += str . charAt ( i ) ; i ++ ; } while ( i < str . length ( ) && str . charAt ( i ) >= '1' && str . charAt ( i ) <= '9' ) { freq = freq * 10 + str . charAt ( i ) - '0' ; i ++ ; } for ( int j = 1 ; j <= freq ; j ++ ) expand += temp ; } if ( freq == 0 ) expand += temp ; return expand . charAt ( k - 1 ) ; } public static void main ( String args [ ] ) { String str = " ab4c12ed3" ; int k = 21 ; System . out . println ( encodedChar ( str , k ) ) ; } }
Converting Decimal Number lying between 1 to 3999 to Roman Numerals | Java Program for above approach ; Function to calculate roman equivalent ; storing roman values of digits from 0 - 9 when placed at different places ; Converting to roman ; Driver program to test above function
class GFG { static String intToRoman ( int num ) { String m [ ] = { " " , " M " , " MM " , " MMM " } ; String c [ ] = { " " , " C " , " CC " , " CCC " , " CD " , " D " , " DC " , " DCC " , " DCCC " , " CM " } ; String x [ ] = { " " , " X " , " XX " , " XXX " , " XL " , " L " , " LX " , " LXX " , " LXXX " , " XC " } ; String i [ ] = { " " , " I " , " II " , " III " , " IV " , " V " , " VI " , " VII " , " VIII " , " IX " } ; String thousands = m [ num / 1000 ] ; String hundereds = c [ ( num % 1000 ) / 100 ] ; String tens = x [ ( num % 100 ) / 10 ] ; String ones = i [ num % 10 ] ; String ans = thousands + hundereds + tens + ones ; return ans ; } public static void main ( String [ ] args ) { int number = 3549 ; System . out . println ( intToRoman ( number ) ) ; } }
Converting Roman Numerals to Decimal lying between 1 to 3999 | Program to convert Roman Numerals to Numbers ; This function returns value of a Roman symbol ; If present value is less than next value , subtract present from next value and add the resultant to the sum variable . ; Driver Code ; Considering inputs given are valid
import java . util . Map ; import java . util . HashMap ; class GFG { private static final Map < Character , Integer > roman = new HashMap < Character , Integer > ( ) { { put ( ' I ' , 1 ) ; put ( ' V ' , 5 ) ; put ( ' X ' , 10 ) ; put ( ' L ' , 50 ) ; put ( ' C ' , 100 ) ; put ( ' D ' , 500 ) ; put ( ' M ' , 1000 ) ; } } ; private static int romanToInt ( String s ) { int sum = 0 ; int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( i != n - 1 && roman . get ( s . charAt ( i ) ) < roman . get ( s . charAt ( i + 1 ) ) ) { sum += roman . get ( s . charAt ( i + 1 ) ) - roman . get ( s . charAt ( i ) ) ; i ++ ; } else { sum += roman . get ( s . charAt ( i ) ) ; } } return sum ; } public static void main ( String [ ] args ) { String input = " MCMIV " ; System . out . print ( " Integer ▁ form ▁ of ▁ Roman ▁ Numeral ▁ is ▁ " + romanToInt ( input ) ) ; } }
Remove extra spaces from a string | * Java Program to remove extra spaces from a string *
public class GFG { public static void main ( String args [ ] ) { String str = " ▁ Hello ▁ Geeks ▁ . ▁ Welcome ▁ , TABSYMBOL Do ▁ you ▁ love ▁ Geeks ▁ , ▁ Geeks ▁ ? ▁ " ; System . out . println ( str . replaceAll ( " \\ s + " , " ▁ " ) . trim ( ) ) ; } }
Longest Common Prefix using Binary Search | A Java Program to find the longest common prefix ; A Function to find the string having the minimum length and returns that length ; A Function that returns the longest common prefix from the array of strings ; We will do an in - place binary search on the first string of the array in the range 0 to index ; Same as ( low + high ) / 2 , but avoids overflow for large low and high ; If all the strings in the input array contains this prefix then append this substring to our answer ; And then go for the right part ; else Go for the left part ; Driver program to test above function
class GFG { static int findMinLength ( String arr [ ] , int n ) { int min = Integer . MAX_VALUE ; for ( int i = 0 ; i <= ( n - 1 ) ; i ++ ) { if ( arr [ i ] . length ( ) < min ) { min = arr [ i ] . length ( ) ; } } return min ; } static boolean allContainsPrefix ( String arr [ ] , int n , String str , int start , int end ) { for ( int i = 0 ; i <= ( n - 1 ) ; i ++ ) { String arr_i = arr [ i ] ; for ( int j = start ; j <= end ; j ++ ) if ( arr_i . charAt ( j ) != str . charAt ( j ) ) return false ; } return true ; } static String commonPrefix ( String arr [ ] , int n ) { int index = findMinLength ( arr , n ) ; int low = 0 , high = index - 1 ; while ( low <= high ) { int mid = low + ( high - low ) / 2 ; if ( allContainsPrefix ( arr , n , arr [ 0 ] , low , mid ) ) { prefix = prefix + arr [ 0 ] . substring ( low , mid + 1 ) ; low = mid + 1 ; } { high = mid - 1 ; } } return prefix ; } public static void main ( String args [ ] ) { String arr [ ] = { " geeksforgeeks " , " geeks " , " geek " , " geezer " } ; int n = arr . length ; String ans = commonPrefix ( arr , n ) ; if ( ans . length ( ) > 0 ) System . out . println ( " The ▁ longest ▁ common " + " ▁ prefix ▁ is ▁ " + ans ) ; else System . out . println ( " There ▁ is ▁ no ▁ common " + " ▁ prefix " ) ; } }
Lower case to upper case | Java program to convert a string to uppercase ; Converts a string to uppercase ; Driver code
class GFG { static String to_upper ( char [ ] in ) { for ( int i = 0 ; i < in . length ; i ++ ) if ( ' a ' <= in [ i ] && in [ i ] <= ' z ' ) in [ i ] &= ~ ( 1 << 5 ) ; return String . valueOf ( in ) ; } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; System . out . println ( to_upper ( str . toCharArray ( ) ) ) ; } }
Longest Common Prefix using Divide and Conquer Algorithm | Java Program to find the longest common prefix ; A Utility Function to find the common prefix between strings - str1 and str2 ; A Divide and Conquer based function to find the longest common prefix . This is similar to the merge sort technique ; Same as ( low + high ) / 2 , but avoids overflow for large low and high ; Driver program to test above function
class GFG { static String commonPrefixUtil ( String str1 , String str2 ) { String result = " " ; int n1 = str1 . length ( ) , n2 = str2 . length ( ) ; for ( int i = 0 , j = 0 ; i <= n1 - 1 && j <= n2 - 1 ; i ++ , j ++ ) { if ( str1 . charAt ( i ) != str2 . charAt ( j ) ) { break ; } result += str1 . charAt ( i ) ; } return ( result ) ; } static String commonPrefix ( String arr [ ] , int low , int high ) { if ( low == high ) { return ( arr [ low ] ) ; } if ( high > low ) { int mid = low + ( high - low ) / 2 ; String str1 = commonPrefix ( arr , low , mid ) ; String str2 = commonPrefix ( arr , mid + 1 , high ) ; return ( commonPrefixUtil ( str1 , str2 ) ) ; } return null ; } public static void main ( String [ ] args ) { String arr [ ] = { " geeksforgeeks " , " geeks " , " geek " , " geezer " } ; int n = arr . length ; String ans = commonPrefix ( arr , 0 , n - 1 ) ; if ( ans . length ( ) != 0 ) { System . out . println ( " The ▁ longest ▁ common ▁ prefix ▁ is ▁ " + ans ) ; } else { System . out . println ( " There ▁ is ▁ no ▁ common ▁ prefix " ) ; } } }
Longest Common Prefix using Word by Word Matching | Java Program to find the longest common prefix ; A Utility Function to find the common prefix between strings - str1 and str2 ; Compare str1 and str2 ; A Function that returns the longest common prefix from the array of strings ; Driver program to test above function
class GFG { static String commonPrefixUtil ( String str1 , String str2 ) { String result = " " ; int n1 = str1 . length ( ) , n2 = str2 . length ( ) ; for ( int i = 0 , j = 0 ; i <= n1 - 1 && j <= n2 - 1 ; i ++ , j ++ ) { if ( str1 . charAt ( i ) != str2 . charAt ( j ) ) { break ; } result += str1 . charAt ( i ) ; } return ( result ) ; } static String commonPrefix ( String arr [ ] , int n ) { String prefix = arr [ 0 ] ; for ( int i = 1 ; i <= n - 1 ; i ++ ) { prefix = commonPrefixUtil ( prefix , arr [ i ] ) ; } return ( prefix ) ; } public static void main ( String [ ] args ) { String arr [ ] = { " geeksforgeeks " , " geeks " , " geek " , " geezer " } ; int n = arr . length ; String ans = commonPrefix ( arr , n ) ; if ( ans . length ( ) > 0 ) { System . out . printf ( " The ▁ longest ▁ common ▁ prefix ▁ is ▁ - ▁ % s " , ans ) ; } else { System . out . printf ( " There ▁ is ▁ no ▁ common ▁ prefix " ) ; } } }
1 ' s ▁ and ▁ 2' s complement of a Binary Number | Java program to print 1 ' s ▁ and ▁ 2' s complement of a binary number ; Returns '0' for '1' and '1' for '0' ; Print 1 ' s ▁ and ▁ 2' s complement of binary number represented by " bin " ; for ones complement flip every bit ; for two 's complement go from right to left in  ones complement and if we get 1 make, we make  them 0 and keep going left when we get first  0, make that 1 and go out of loop ; If No break : all are 1 as in 111 or 11111 ; in such case , add extra 1 at beginning ; Driver code
class GFG { static char flip ( char c ) { return ( c == '0' ) ? '1' : '0' ; } static void printOneAndTwosComplement ( String bin ) { int n = bin . length ( ) ; int i ; String ones = " " , twos = " " ; ones = twos = " " ; for ( i = 0 ; i < n ; i ++ ) { ones += flip ( bin . charAt ( i ) ) ; } twos = ones ; for ( i = n - 1 ; i >= 0 ; i -- ) { if ( ones . charAt ( i ) == '1' ) { twos = twos . substring ( 0 , i ) + '0' + twos . substring ( i + 1 ) ; } else { twos = twos . substring ( 0 , i ) + '1' + twos . substring ( i + 1 ) ; break ; } } if ( i == - 1 ) { twos = '1' + twos ; } System . out . println ( "1 ' s ▁ complement : ▁ " + ones ) ; ; System . out . println ( "2 ' s ▁ complement : ▁ " + twos ) ; } public static void main ( String [ ] args ) { String bin = "1100" ; printOneAndTwosComplement ( bin ) ; } }
Print Concatenation of Zig | Java Program for above approach ; Function for zig - zag Concatenation ; Check is n is less or equal to 1 ; Iterate rowNum from 0 to n - 1 ; Iterate i till s . length ( ) - 1 ; Check is rowNum is 0 or n - 1 ; Driver Code
import java . lang . * ; class Solution { private static String zigZagConcat ( String s , int n ) { if ( n <= 1 ) { return s ; } StringBuilder result = new StringBuilder ( ) ; for ( int rowNum = 0 ; rowNum < n ; rowNum ++ ) { int i = rowNum ; boolean up = true ; while ( i < s . length ( ) ) { result = result . append ( s . charAt ( i ) ) ; if ( rowNum == 0 rowNum == n - 1 ) { i += ( 2 * n - 2 ) ; } else { if ( up ) { i += ( 2 * ( n - rowNum ) - 2 ) ; } else { i += rowNum * 2 ; } up ^= true ; } } } return result . toString ( ) ; } public static void main ( String [ ] args ) { String str = " GEEKSFORGEEKS " ; int n = 3 ; System . out . println ( zigZagConcat ( str , n ) ) ; } }