codeparrot/xlcost-text-to-code huggingface dataset:
Number of palindromic permutations | Set 1 | Java program to find number of palindromic permutations of a given string ; Returns factorial of n ; Returns count of palindromic permutations of str . ; Count frequencies of all characters ; Since half of the characters decide count of palindromic permutations , we take ( n / 2 ) ! ; To make sure that there is at most one odd occurring char ; Traverse through all counts ; To make sure that the string can permute to form a palindrome ; If there are more than one odd occurring chars ; Divide all permutations with repeated characters ; Driver code
class GFG { static final int MAX = 256 ; static long fact ( int n ) { long res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } static int countPalinPermutations ( String str ) { int n = str . length ( ) ; int freq [ ] = new int [ MAX ] ; for ( int i = 0 ; i < n ; i ++ ) freq [ str . charAt ( i ) ] ++ ; long res = fact ( n / 2 ) ; boolean oddFreq = false ; for ( int i = 0 ; i < MAX ; i ++ ) { int half = freq [ i ] / 2 ; if ( freq [ i ] % 2 != 0 ) { if ( oddFreq == true ) return 0 ; oddFreq = true ; } res = res / fact ( half ) ; } return ( int ) res ; } public static void main ( String [ ] args ) { String str = " gffg " ; System . out . print ( countPalinPermutations ( str ) ) ; } }
Rearrange characters to form palindrome if possible | Java program to rearrange a string to make palindrome ; Store counts of characters ; Find the number of odd elements . Takes O ( n ) ; odd_cnt = 1 only if the length of str is odd ; Generate first halh of palindrome ; Build a string of floor ( count / 2 ) occurrences of current character ; Attach the built string to end of and begin of second half ; Insert odd character if there is any ; Driver code
import java . util . HashMap ; import java . util . Map . Entry ; class GFG { public static String getPalindrome ( String str ) { HashMap < Character , Integer > counting = new HashMap < > ( ) ; for ( char ch : str . toCharArray ( ) ) { if ( counting . containsKey ( ch ) ) { counting . put ( ch , counting . get ( ch ) + 1 ) ; } else { counting . put ( ch , 1 ) ; } } int oddCount = 0 ; char oddChar = 0 ; for ( Entry < Character , Integer > itr : counting . entrySet ( ) ) { if ( itr . getValue ( ) % 2 != 0 ) { oddCount ++ ; oddChar = itr . getKey ( ) ; } } if ( oddCount > 1 || oddCount == 1 && str . length ( ) % 2 == 0 ) { return " NO ▁ PALINDROME " ; } String firstHalf = " " , lastHalf = " " ; for ( Entry < Character , Integer > itr : counting . entrySet ( ) ) { String ss = " " ; for ( int i = 0 ; i < itr . getValue ( ) / 2 ; i ++ ) { ss += itr . getKey ( ) ; } firstHalf = firstHalf + ss ; lastHalf = ss + lastHalf ; } return ( oddCount == 1 ) ? ( firstHalf + oddChar + lastHalf ) : ( firstHalf + lastHalf ) ; } public static void main ( String [ ] args ) { String str = " mdaam " ; System . out . println ( getPalindrome ( str ) ) ; } }
Substrings starting with vowel and ending with consonants and vice versa | Java program to count special strings ; Returns true if ch is vowel ; function to check consonant ; in case of empty string , we can 't fullfill the  required condition, hence we return ans as 0. ; co [ i ] is going to store counts of consonants from str [ len - 1 ] to str [ i ] . vo [ i ] is going to store counts of vowels from str [ len - 1 ] to str [ i ] . ; Counting consonants and vowels from end of string . ; Now we traverse string from beginning ; If vowel , then count of substrings starting with str [ i ] is equal to count of consonants after it . ; If consonant , then count of substrings starting with str [ i ] is equal to count of vowels after it . ; Driver program
class GfG { static boolean isVowel ( char ch ) { return ( ch == ' a ' ch == ' e ' ch == ' i ' ch == ' o ' ch == ' u ' ) ; } static boolean isCons ( char ch ) { return ( ch != ' a ' && ch != ' e ' && ch != ' i ' && ch != ' o ' && ch != ' u ' ) ; } static int countSpecial ( char [ ] str ) { int len = str . length ; if ( len == 0 ) return 0 ; int co [ ] = new int [ len + 1 ] ; int vo [ ] = new int [ len + 1 ] ; if ( isCons ( str [ len - 1 ] ) == true ) co [ len - 1 ] = 1 ; else vo [ len - 1 ] = 1 ; for ( int i = len - 2 ; i >= 0 ; i -- ) { if ( isCons ( str [ i ] ) == true ) { co [ i ] = co [ i + 1 ] + 1 ; vo [ i ] = vo [ i + 1 ] ; } else { co [ i ] = co [ i + 1 ] ; vo [ i ] = vo [ i + 1 ] + 1 ; } } long ans = 0 ; for ( int i = 0 ; i < len ; i ++ ) { if ( isVowel ( str [ i ] ) ) ans = ans + co [ i + 1 ] ; else ans = ans + vo [ i + 1 ] ; } return ( int ) ans ; } public static void main ( String [ ] args ) { String str = " adceba " ; System . out . println ( countSpecial ( str . toCharArray ( ) ) ) ; } }
Convert the string into palindrome string by changing only one character | Java program to Check if it is possible to convert the string into palindrome string by changing only one character . ; Function to check if it is possible to convert the string into palindrome ; Counting number of characters that should be changed . ; If count of changes is less than or equal to 1 ; Driver Function
import java . io . * ; class GFG { static boolean checkPalindrome ( String str ) { int n = str . length ( ) ; int count = 0 ; for ( int i = 0 ; i < n / 2 ; ++ i ) if ( str . charAt ( i ) != str . charAt ( n - i - 1 ) ) ++ count ; return ( count <= 1 ) ; } public static void main ( String [ ] args ) { String str = " abccaa " ; if ( checkPalindrome ( str ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Counting even decimal value substrings in a binary string | Java Program to count all even decimal value substring . ; function return count of even decimal value substring ; store the count of even decimal value substring ; substring started with '0' ; increment result by ( n - i ) because all substring which are generate by this character produce even decimal value . ; Driver code
import java . io . * ; class GFG { static int evenDecimalValue ( String str , int n ) { int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) == '0' ) { result += ( n - i ) ; } } return result ; } public static void main ( String [ ] args ) { String str = "10010" ; int n = 5 ; System . out . println ( evenDecimalValue ( str , n ) ) ; } }
Number of substrings with odd decimal value in a binary string | Java program to count substrings with odd decimal value ; function to count number of substrings with odd decimal representation ; auxiliary array to store count of 1 's before ith index ; store count of 1 's before  i-th index ; variable to store answer ; traverse the string reversely to calculate number of odd substrings before i - th index ; Driver code
import java . io . * ; import java . util . * ; class GFG { static int countSubstr ( String s ) { int n = s . length ( ) ; int [ ] auxArr = new int [ n ] ; if ( s . charAt ( 0 ) == '1' ) auxArr [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( s . charAt ( i ) == '1' ) auxArr [ i ] = auxArr [ i - 1 ] + 1 ; else auxArr [ i ] = auxArr [ i - 1 ] ; } int count = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) if ( s . charAt ( i ) == '1' ) count += auxArr [ i ] ; return count ; } public static void main ( String [ ] args ) { String s = "1101" ; System . out . println ( countSubstr ( s ) ) ; } }
Find the starting indices of the substrings in string ( S ) which is made by concatenating all words from a list ( L ) | Java program to calculate the starting indices of substrings inside S which contains all the words present in List L . ; Returns an integer vector consisting of starting indices of substrings present inside the string S ; Number of a characters of a word in list L . ; Number of words present inside list L . ; Total characters present in list L . ; Resultant vector which stores indices . ; If the total number of characters in list L is more than length of string S itself . ; Map stores the words present in list L against it 's occurrences inside list L  ; Traverse the substring ; Extract the word ; If word not found or if frequency of current word is more than required simply break . ; Else decrement the count of word from hash_map ; Store the starting index of that substring when all the words in the list are in substring ; Driver code
import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashMap ; import java . util . List ; class GFG { public static ArrayList < Integer > findSubstring ( String A , final List < String > B ) { int size_word = B . get ( 0 ) . length ( ) ; int word_count = B . size ( ) ; int size_l = size_word * word_count ; ArrayList < Integer > res = new ArrayList < Integer > ( ) ; int n = A . length ( ) ; if ( size_l > n ) { return res ; } HashMap < String , Integer > hashMap = new HashMap < String , Integer > ( ) ; for ( String word : B ) { hashMap . put ( word , hashMap . getOrDefault ( word , 0 ) + 1 ) ; } for ( int i = 0 ; i <= n - size_l ; i ++ ) { HashMap < String , Integer > tempMap = ( HashMap < String , Integer > ) hashMap . clone ( ) ; int j = i , count = word_count ; while ( j < i + size_l ) { String word = A . substring ( j , j + size_word ) ; if ( ! hashMap . containsKey ( word ) || tempMap . get ( word ) == 0 ) { break ; } else { tempMap . put ( word , tempMap . get ( word ) - 1 ) ; count -- ; } j += size_word ; } if ( count == 0 ) { res . add ( i ) ; } } return res ; } public static void main ( String [ ] args ) { String S = " barfoothefoobarman " ; ArrayList < String > L = new ArrayList < > ( Arrays . asList ( " foo " , " bar " ) ) ; ArrayList < Integer > indices = findSubstring ( S , L ) ; for ( Integer i : indices ) { System . out . println ( i ) ; } } }
Check whether second string can be formed from characters of first string | Java program to check whether second string can be formed from first string ; Create a count array and count frequencies characters in str1 . ; Now traverse through str2 to check if every character has enough counts ; Driver Code
class GFG { static int MAX = 256 ; static boolean canMakeStr2 ( String str1 , String str2 ) { int [ ] count = new int [ MAX ] ; char [ ] str3 = str1 . toCharArray ( ) ; for ( int i = 0 ; i < str3 . length ; i ++ ) count [ str3 [ i ] ] ++ ; char [ ] str4 = str2 . toCharArray ( ) ; for ( int i = 0 ; i < str4 . length ; i ++ ) { if ( count [ str4 [ i ] ] == 0 ) return false ; count [ str4 [ i ] ] -- ; } return true ; } static public void main ( String [ ] args ) { String str1 = " geekforgeeks " ; String str2 = " for " ; if ( canMakeStr2 ( str1 , str2 ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Position of robot after given movements | Java implementation to find final position of robot after the complete movement ; function to find final position of robot after the complete movement ; traverse the instruction string ' move ' ; for each movement increment its respective counter ; required final position of robot ; Driver code
import java . io . * ; class GFG { static void finalPosition ( String move ) { int l = move . length ( ) ; int countUp = 0 , countDown = 0 ; int countLeft = 0 , countRight = 0 ; for ( int i = 0 ; i < l ; i ++ ) { if ( move . charAt ( i ) == ' U ' ) countUp ++ ; else if ( move . charAt ( i ) == ' D ' ) countDown ++ ; else if ( move . charAt ( i ) == ' L ' ) countLeft ++ ; else if ( move . charAt ( i ) == ' R ' ) countRight ++ ; } System . out . println ( " Final ▁ Position : ▁ ( " + ( countRight - countLeft ) + " , ▁ " + ( countUp - countDown ) + " ) " ) ; } public static void main ( String [ ] args ) { String move = " UDDLLRUUUDUURUDDUULLDRRRR " ; finalPosition ( move ) ; } }
Length of longest balanced parentheses prefix | Java Program to find length of longest balanced parentheses prefix . ; Return the length of longest balanced parentheses prefix . ; Traversing the string . ; If open bracket add 1 to sum . ; If closed bracket subtract 1 from sum ; if first bracket is closing bracket then this condition would help ; If sum is 0 , store the index value . ; Driven Program
import java . io . * ; class GFG { static int maxbalancedprefix ( String str , int n ) { int sum = 0 ; int maxi = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) == ' ( ' ) sum += 1 ; else sum -= 1 ; if ( sum < 0 ) break ; if ( sum == 0 ) maxi = i + 1 ; } return maxi ; } public static void main ( String [ ] args ) { String str = " ( ( ( ) ( ) ) ( ) ) ( ( " ; int n = str . length ( ) ; System . out . println ( maxbalancedprefix ( str , n ) ) ; } }
Minimum cost to convert string into palindrome | Java program to find minimum cost to make a palindrome . ; Function to return cost ; length of string ; Iterate from both sides of string . If not equal , a cost will be there ; Driver code
import java . io . * ; class GFG { static int cost ( String str ) { int len = str . length ( ) ; int res = 0 ; for ( int i = 0 , j = len - 1 ; i < j ; i ++ , j -- ) if ( str . charAt ( i ) != str . charAt ( j ) ) res += Math . min ( str . charAt ( i ) , str . charAt ( j ) ) - ' a ' + 1 ; return res ; } public static void main ( String [ ] args ) { String str = " abcdef " ; System . out . println ( cost ( str ) ) ; } }
Encoding a word into Pig Latin | Java program to encode a word to a Pig Latin . ; the index of the first vowel is stored . ; Pig Latin is possible only if vowels is present ; Take all characters after index ( including index ) . Append all characters which are before index . Finally append " ay " ; Driver code
class GFG { static boolean isVowel ( char c ) { return ( c == ' A ' c == ' E ' c == ' I ' c == ' O ' c == ' U ' c == ' a ' c == ' e ' c == ' i ' c == ' o ' c == ' u ' ) ; } static String pigLatin ( String s ) { int len = s . length ( ) ; int index = - 1 ; for ( int i = 0 ; i < len ; i ++ ) { if ( isVowel ( s . charAt ( i ) ) ) { index = i ; break ; } } if ( index == - 1 ) return " - 1" ; return s . substring ( index ) + s . substring ( 0 , index ) + " ay " ; } public static void main ( String [ ] args ) { String str = pigLatin ( " graphic " ) ; if ( str == " - 1" ) System . out . print ( " No ▁ vowels ▁ found . " + " Pig ▁ Latin ▁ not ▁ possible " ) ; else System . out . print ( str ) ; } }
Possibility of a word from a given set of characters | java program to check if a query string is present is given set . ; Count occurrences of all characters in s . ; Check if number of occurrences of every character in q is less than or equal to that in s . ; driver program
import java . io . * ; public class GFG { static int MAX_CHAR = 256 ; static boolean isPresent ( String s , String q ) { int [ ] freq = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) freq [ s . charAt ( i ) ] ++ ; for ( int i = 0 ; i < q . length ( ) ; i ++ ) { freq [ q . charAt ( i ) ] -- ; if ( freq [ q . charAt ( i ) ] < 0 ) return false ; } return true ; } static public void main ( String [ ] args ) { String s = " abctd " ; String q = " cat " ; if ( isPresent ( s , q ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Minimum reduce operations to convert a given string into a palindrome | Java program to count minimum reduce operations to make a palindrome ; Returns count of minimum character reduce operations to make palindrome . ; Compare every character of first half with the corresponding character of second half and add difference to result . ; Driver code
import java . io . * ; class GFG { static int countReduce ( String str ) { int n = str . length ( ) ; int res = 0 ; for ( int i = 0 ; i < n / 2 ; i ++ ) res += Math . abs ( str . charAt ( i ) - str . charAt ( n - i - 1 ) ) ; return res ; } public static void main ( String [ ] args ) { String str = " abcd " ; System . out . println ( countReduce ( str ) ) ; } }
Minimal operations to make a number magical | java program to make a number magical ; function to calculate the minimal changes ; maximum digits that can be changed ; nested loops to generate all 6 digit numbers ; counter to count the number of change required ; if first digit is equal ; if 2 nd digit is equal ; if 3 rd digit is equal ; if 4 th digit is equal ; if 5 th digit is equal ; if 6 th digit is equal ; checks if less then the previous calculate changes ; returns the answer ; Driver code ; number stored in string ; prints the minimum operations
import java . io . * ; class GFG { static int calculate ( String s ) { int ans = 6 ; for ( int i = 0 ; i < 10 ; ++ i ) { for ( int j = 0 ; j < 10 ; ++ j ) { for ( int k = 0 ; k < 10 ; ++ k ) { for ( int l = 0 ; l < 10 ; ++ l ) { for ( int m = 0 ; m < 10 ; ++ m ) { for ( int n = 0 ; n < 10 ; ++ n ) { if ( i + j + k == l + m + n ) { int c = 0 ; if ( i != s . charAt ( 0 ) - '0' ) c ++ ; if ( j != s . charAt ( 1 ) - '0' ) c ++ ; if ( k != s . charAt ( 2 ) - '0' ) c ++ ; if ( l != s . charAt ( 3 ) - '0' ) c ++ ; if ( m != s . charAt ( 4 ) - '0' ) c ++ ; if ( n != s . charAt ( 5 ) - '0' ) c ++ ; if ( c < ans ) ans = c ; } } } } } } } return ans ; } static public void main ( String [ ] args ) { String s = "123456" ; System . out . println ( calculate ( s ) ) ; } }
Check if a two character string can be made using given words | Java code to check if a two character string can be made using given strings ; Function to check if str can be made using given words ; If str itself is present ; Match first character of str with second of word and vice versa ; If both characters found . ; Driver Code
import java . util . * ; class GFG { static boolean makeAndCheckString ( Vector < String > words , String str ) { int n = words . size ( ) ; boolean first = false , second = false ; for ( int i = 0 ; i < n ; i ++ ) { if ( words . get ( i ) == str ) return true ; if ( str . charAt ( 0 ) == words . get ( i ) . charAt ( 1 ) ) first = true ; if ( str . charAt ( 1 ) == words . get ( i ) . charAt ( 0 ) ) second = true ; if ( first && second ) return true ; } return false ; } public static void main ( String [ ] args ) { String str = " ya " ; String [ ] array = { " ah " , " oy " , " to " , " ha " } ; Vector < String > words = new Vector < String > ( Arrays . asList ( array ) ) ; if ( makeAndCheckString ( words , str ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Print N | Java program to print all N - bit binary ; Function to get the binary representation of the number N ; loop for each bit ; generate numbers in the range of ( 2 ^ N ) - 1 to 2 ^ ( N - 1 ) inclusive ; longest prefix check ; if counts of 1 is greater than counts of zero ; do sub - prefixes check ; Driver code ; Function call
import java . io . * ; import java . util . * ; class GFG { static String getBinaryRep ( int N , int num_of_bits ) { String r = " " ; num_of_bits -- ; while ( num_of_bits >= 0 ) { if ( ( N & ( 1 << num_of_bits ) ) != 0 ) r += "1" ; else r += "0" ; num_of_bits -- ; } return r ; } static ArrayList < String > NBitBinary ( int N ) { ArrayList < String > r = new ArrayList < String > ( ) ; int first = 1 << ( N - 1 ) ; int last = first * 2 ; for ( int i = last - 1 ; i >= first ; -- i ) { int zero_cnt = 0 ; int one_cnt = 0 ; int t = i ; int num_of_bits = 0 ; while ( t > 0 ) { if ( ( t & 1 ) != 0 ) one_cnt ++ ; else zero_cnt ++ ; num_of_bits ++ ; t = t >> 1 ; } if ( one_cnt >= zero_cnt ) { boolean all_prefix_match = true ; int msk = ( 1 << num_of_bits ) - 2 ; int prefix_shift = 1 ; while ( msk > 0 ) { int prefix = ( msk & i ) >> prefix_shift ; int prefix_one_cnt = 0 ; int prefix_zero_cnt = 0 ; while ( prefix > 0 ) { if ( ( prefix & 1 ) != 0 ) prefix_one_cnt ++ ; else prefix_zero_cnt ++ ; prefix = prefix >> 1 ; } if ( prefix_zero_cnt > prefix_one_cnt ) { all_prefix_match = false ; break ; } prefix_shift ++ ; msk = msk & ( msk << 1 ) ; } if ( all_prefix_match ) { r . add ( getBinaryRep ( i , num_of_bits ) ) ; } } } return r ; } public static void main ( String [ ] args ) { int n = 4 ; ArrayList < String > results = NBitBinary ( n ) ; for ( int i = 0 ; i < results . size ( ) ; ++ i ) System . out . print ( results . get ( i ) + " ▁ " ) ; System . out . println ( ) ; } }
Find winner of an election where votes are represented as candidate names | Java program to find winner in an election . ; We have four Candidates with name as ' John ' , ' Johnny ' , ' jamie ' , ' jackie ' . The votes in String array are as per the votes casted . Print the name of candidates received Max vote . ; Insert all votes in a hashmap ; Traverse through map to find the candidate with maximum votes . ; If there is a tie , pick lexicographically smaller . ; Driver code
import java . util . * ; public class ElectoralVotingBallot { public static void findWinner ( String votes [ ] ) { Map < String , Integer > map = new HashMap < String , Integer > ( ) ; for ( String str : votes ) { if ( map . keySet ( ) . contains ( str ) ) map . put ( str , map . get ( str ) + 1 ) ; else map . put ( str , 1 ) ; } int maxValueInMap = 0 ; String winner = " " ; for ( Map . Entry < String , Integer > entry : map . entrySet ( ) ) { String key = entry . getKey ( ) ; Integer val = entry . getValue ( ) ; if ( val > maxValueInMap ) { maxValueInMap = val ; winner = key ; } else if ( val == maxValueInMap && winner . compareTo ( key ) > 0 ) winner = key ; } System . out . println ( winner ) ; } public static void main ( String [ ] args ) { String [ ] votes = { " john " , " johnny " , " jackie " , " johnny " , " john " , " jackie " , " jamie " , " jamie " , " john " , " johnny " , " jamie " , " johnny " , " john " } ; findWinner ( votes ) ; } }
Luhn algorithm | Java program to implement Luhn algorithm ; Returns true if given card number is valid ; We add two digits to handle cases that make two digits after doubling ; Driver code
import java . io . * ; class GFG { static boolean checkLuhn ( String cardNo ) { int nDigits = cardNo . length ( ) ; int nSum = 0 ; boolean isSecond = false ; for ( int i = nDigits - 1 ; i >= 0 ; i -- ) { int d = cardNo . charAt ( i ) - '0' ; if ( isSecond == true ) d = d * 2 ; nSum += d / 10 ; nSum += d % 10 ; isSecond = ! isSecond ; } return ( nSum % 10 == 0 ) ; } static public void main ( String [ ] args ) { String cardNo = "79927398713" ; if ( checkLuhn ( cardNo ) ) System . out . println ( " This ▁ is ▁ a ▁ valid ▁ card " ) ; else System . out . println ( " This ▁ is ▁ not ▁ a ▁ valid ▁ card " ) ; } }
Distributing all balls without repetition | Java program to find if its possible to distribute balls without repitiio ; function to find if its possible to distribute balls or not ; count array to count how many times each color has occurred ; increasing count of each color every time it appears ; to check if any color appears more than K times if it does we will print NO ; Driver code
import java . io . * ; public class GFG { static int MAX_CHAR = 26 ; static boolean distributingBalls ( long k , long n , String str ) { int [ ] a = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ str . charAt ( i ) - ' a ' ] ++ ; } for ( int i = 0 ; i < MAX_CHAR ; i ++ ) if ( a [ i ] > k ) return false ; return true ; } static public void main ( String [ ] args ) { long n = 6 , k = 3 ; String str = " aacaab " ; if ( distributingBalls ( k , n , str ) ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } }
Find substrings that contain all vowels | Java program to find all substring that contain all vowels ; Returns true if x is vowel . ; Function to check whether a character is vowel or not ; Outer loop picks starting character and inner loop picks ending character . ; If current character is not vowel , then no more result substrings possible starting from str [ i ] . ; If vowel , then we insert it in hash ; If all vowels are present in current substring ; Driver code
import java . util . HashSet ; public class GFG { static boolean isVowel ( char x ) { return ( x == ' a ' x == ' e ' x == ' i ' x == ' o ' x == ' u ' ) ; } static void findSubstring ( String str ) { HashSet < Character > hash = new HashSet < Character > ( ) ; int n = str . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { if ( isVowel ( str . charAt ( j ) ) == false ) break ; hash . add ( str . charAt ( j ) ) ; if ( hash . size ( ) == 5 ) System . out . print ( str . substring ( i , j + 1 ) + " ▁ " ) ; } hash . clear ( ) ; } } public static void main ( String [ ] args ) { String str = " aeoibsddaeiouudb " ; findSubstring ( str ) ; } }