codeparrot/xlcost-text-to-code huggingface dataset:
Smallest substring with each letter occurring both in uppercase and lowercase | C ++ program for the above approach ; Function to check if the current string is balanced or not ; For every character , check if there exists uppercase as well as lowercase characters ; Function to find smallest length substring in the given string which is balanced ; Store frequency of lowercase characters ; Stores frequency of uppercase characters ; Count frequency of characters ; Mark those characters which are not present in both lowercase and uppercase ; Initialize the frequencies back to 0 ; Marks the start and end of current substring ; Marks the start and end of required substring ; Stores the length of smallest balanced substring ; Remove all characters obtained so far ; Remove extra characters from front of the current substring ; If substring ( st , i ) is balanced ; No balanced substring ; Store answer string ; Driver Code ; Given string
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool balanced ( int small [ ] , int caps [ ] ) { for ( int i = 0 ; i < 26 ; i ++ ) { if ( small [ i ] != 0 && ( caps [ i ] == 0 ) ) return 0 ; else if ( ( small [ i ] == 0 ) && ( caps [ i ] != 0 ) ) return 0 ; } return 1 ; } void smallestBalancedSubstring ( string s ) { int small [ 26 ] ; int caps [ 26 ] ; memset ( small , 0 , sizeof ( small ) ) ; memset ( caps , 0 , sizeof ( caps ) ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s [ i ] >= 65 && s [ i ] <= 90 ) caps [ s [ i ] - ' A ' ] ++ ; else small [ s [ i ] - ' a ' ] ++ ; } unordered_map < char , int > mp ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( small [ i ] && ! caps [ i ] ) mp [ char ( i + ' a ' ) ] = 1 ; else if ( caps [ i ] && ! small [ i ] ) mp [ char ( i + ' A ' ) ] = 1 ; } memset ( small , 0 , sizeof ( small ) ) ; memset ( caps , 0 , sizeof ( caps ) ) ; int i = 0 , st = 0 ; int start = -1 , end = -1 ; int minm = INT_MAX ; while ( i < s . length ( ) ) { if ( mp [ s [ i ] ] ) { while ( st < i ) { if ( s [ st ] >= 65 && s [ st ] <= 90 ) caps [ s [ st ] - ' A ' ] -- ; else small [ s [ st ] - ' a ' ] -- ; st ++ ; } i += 1 ; st = i ; } else { if ( s [ i ] >= 65 && s [ i ] <= 90 ) caps [ s [ i ] - ' A ' ] ++ ; else small [ s [ i ] - ' a ' ] ++ ; while ( 1 ) { if ( s [ st ] >= 65 && s [ st ] <= 90 && caps [ s [ st ] - ' A ' ] > 1 ) { caps [ s [ st ] - ' A ' ] -- ; st ++ ; } else if ( s [ st ] >= 97 && s [ st ] <= 122 && small [ s [ st ] - ' a ' ] > 1 ) { small [ s [ st ] - ' a ' ] -- ; st ++ ; } else break ; } if ( balanced ( small , caps ) ) { if ( minm > ( i - st + 1 ) ) { minm = i - st + 1 ; start = st ; end = i ; } } i += 1 ; } } if ( start == -1 end == -1 ) cout << -1 << endl ; else { string ans = " " ; for ( int i = start ; i <= end ; i ++ ) ans += s [ i ] ; cout << ans << endl ; } } int main ( ) { string s = " azABaabba " ; smallestBalancedSubstring ( s ) ; return 0 ; }
Pair of strings having longest common prefix of maximum length in given array | C ++ program to implement the above approach ; Structure of Trie ; Function to insert a string into Trie ; Stores length of the string ; Traverse the string str ; If str [ i ] is not present in current path of Trie ; Create a new node of Trie ; Update root ; Function to find the maximum length of longest common prefix in Trie with str ; Stores length of str ; Stores length of longest common prefix in Trie with str ; Traverse the string str ; If str [ i ] is present in the current path of Trie ; Update len ; Update root ; Function to print the pair having maximum length of the longest common prefix ; Stores index of the string having maximum length of longest common prefix ; Stores maximum length of longest common prefix . ; Create root node of Trie ; Insert arr [ 0 ] into Trie ; Traverse the array . ; Stores maximum length of longest common prefix in Trie with arr [ i ] ; If temp is greater than len ; Update len ; Update idx ; Traverse array arr [ ] ; Stores length of arr [ i ] ; Check if maximum length of longest common prefix > M ; Traverse string arr [ i ] and arr [ j ] ; If current character of both string does not match . ; Print pairs having maximum length of the longest common prefix ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct TrieNode { TrieNode * child [ 256 ] ; TrieNode ( ) { child [ 0 ] = child [ 1 ] = NULL ; } } ; void insertTrie ( TrieNode * root , string str ) { int M = str . length ( ) ; for ( int i = 0 ; i < M ; i ++ ) { if ( ! root -> child [ str [ i ] ] ) { root -> child [ str [ i ] ] = new TrieNode ( ) ; } root = root -> child [ str [ i ] ] ; } } int findStrLen ( TrieNode * root , string str ) { int M = str . length ( ) ; int len = 0 ; for ( int i = 0 ; i < M ; i ++ ) { if ( root -> child [ str [ i ] ] ) { len ++ ; root = root -> child [ str [ i ] ] ; } else { return len ; } } return len ; } void findMaxLenPair ( vector < string > & arr , int N ) { int idx = -1 ; int len = 0 ; TrieNode * root = new TrieNode ( ) ; insertTrie ( root , arr [ 0 ] ) ; for ( int i = 1 ; i < N ; i ++ ) { int temp = findStrLen ( root , arr [ i ] ) ; if ( temp > len ) { len = temp ; idx = i ; } insertTrie ( root , arr [ i ] ) ; } for ( int i = 0 ; i < N ; i ++ ) { int M = arr [ i ] . length ( ) ; if ( i != idx && M >= len ) { bool found = true ; for ( int j = 0 ; j < len ; j ++ ) { if ( arr [ i ] [ j ] != arr [ idx ] [ j ] ) { found = false ; break ; } } if ( found ) { cout << " ( " << arr [ i ] << " , ▁ " << arr [ idx ] << " ) " ; return ; } } } } int main ( ) { vector < string > arr = { " geeksforgeeks " , " geeks " , " geeksforcse " } ; int N = arr . size ( ) ; findMaxLenPair ( arr , N ) ; }
Convert given string to another by minimum replacements of subsequences by its smallest character | C ++ program for the above approach ; Function to return the minimum number of operation ; Storing data ; Initialize both arrays ; Stores the index of character ; Filling str1array , convChar and hashmap convertMap . ; Not possible to convert ; Calculate result Initializing return values ; Iterating the character from the end ; Increment the number of operations ; Not possible to convert ; to check whether the final element has been added in set S or not . ; Check if v1 [ j ] is present in hashmap or not ; Already converted then then continue ; Not possible to convert ; Print the result ; Driver Code ; Given strings ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void transformString ( string str1 , string str2 ) { int N = str1 . length ( ) ; vector < int > convChar [ 26 ] ; vector < int > str1array [ 26 ] ; for ( int i = 0 ; i < 26 ; i ++ ) { vector < int > v ; convChar [ i ] = v ; str1array [ i ] = v ; } map < int , char > convertMap ; for ( int i = 0 ; i < N ; i ++ ) { str1array [ str1 [ i ] - ' a ' ] . push_back ( i ) ; } for ( int i = 0 ; i < N ; i ++ ) { if ( str1 [ i ] < str2 [ i ] ) { cout << -1 << endl ; return ; } else if ( str1 [ i ] == str2 [ i ] ) continue ; else { convChar [ str2 [ i ] - ' a ' ] . push_back ( i ) ; convertMap [ i ] = str2 [ i ] ; } } int ret = 0 ; vector < vector < int > > retv ; for ( int i = 25 ; i >= 0 ; i -- ) { vector < int > v = convChar [ i ] ; if ( v . size ( ) == 0 ) continue ; ret ++ ; vector < int > v1 = str1array [ i ] ; if ( v1 . size ( ) == 0 ) { cout << -1 << endl ; return ; } bool isScompleted = false ; for ( int j = 0 ; j < v1 . size ( ) ; j ++ ) { if ( convertMap . find ( v1 [ j ] ) != convertMap . end ( ) ) { char a = convertMap [ v1 [ j ] ] ; if ( a > i + ' a ' ) continue ; else { v . push_back ( v1 [ j ] ) ; isScompleted = true ; retv . push_back ( v ) ; break ; } } else { v . push_back ( v1 [ j ] ) ; isScompleted = true ; retv . push_back ( v ) ; break ; } } if ( ! isScompleted ) { cout << -1 << endl ; return ; } } cout << ret << endl ; } int main ( ) { string A = " abcab " ; string B = " aabab " ; transformString ( A , B ) ; return 0 ; }
Find largest subtree having identical left and right subtrees | C ++ program to find the largest subtree having identical left and right subtree ; A binary tree node has data , pointer to left child and a pointer to right child ; Helper function that allocates a new node with the given data and NULL left and right pointers . ; Sets maxSize to size of largest subtree with identical left and right . maxSize is set with size of the maximum sized subtree . It returns size of subtree rooted with current node . This size is used to keep track of maximum size . ; string to store structure of left and right subtrees ; traverse left subtree and finds its size ; traverse right subtree and finds its size ; if left and right subtrees are similar update maximum subtree if needed ( Note that left subtree may have a bigger value than right and vice versa ) ; append left subtree data ; append current node data ; append right subtree data ; function to find the largest subtree having identical left and right subtree ; Driver program to test above functions ; Let us construct the following Tree 50 / \ 10 60 / \ / \ 5 20 70 70 / \ / \ 65 80 65 80
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int data ; Node * left , * right ; } ; Node * newNode ( int data ) { Node * node = new Node ; node -> data = data ; node -> left = node -> right = NULL ; return ( node ) ; } int largestSubtreeUtil ( Node * root , string & str , int & maxSize , Node * & maxNode ) { if ( root == NULL ) return 0 ; string left = " " , right = " " ; int ls = largestSubtreeUtil ( root -> left , left , maxSize , maxNode ) ; int rs = largestSubtreeUtil ( root -> right , right , maxSize , maxNode ) ; int size = ls + rs + 1 ; if ( left . compare ( right ) == 0 ) { if ( size > maxSize ) { maxSize = size ; maxNode = root ; } } str . append ( " ▁ " ) . append ( left ) . append ( " ▁ " ) ; str . append ( " ▁ " ) . append ( to_string ( root -> data ) ) . append ( " ▁ " ) ; str . append ( " ▁ " ) . append ( right ) . append ( " ▁ " ) ; return size ; } int largestSubtree ( Node * node , Node * & maxNode ) { int maxSize = 0 ; string str = " " ; largestSubtreeUtil ( node , str , maxSize , maxNode ) ; return maxSize ; } int main ( ) { Node * root = newNode ( 50 ) ; root -> left = newNode ( 10 ) ; root -> right = newNode ( 60 ) ; root -> left -> left = newNode ( 5 ) ; root -> left -> right = newNode ( 20 ) ; root -> right -> left = newNode ( 70 ) ; root -> right -> left -> left = newNode ( 65 ) ; root -> right -> left -> right = newNode ( 80 ) ; root -> right -> right = newNode ( 70 ) ; root -> right -> right -> left = newNode ( 65 ) ; root -> right -> right -> right = newNode ( 80 ) ; Node * maxNode = NULL ; int maxSize = largestSubtree ( root , maxNode ) ; cout << " Largest ▁ Subtree ▁ is ▁ rooted ▁ at ▁ node ▁ " << maxNode -> data << " and its size is " << maxSize ; return 0 ; }
Smallest number containing all possible N length permutations using digits 0 to D | C ++ Program to find the minimum length string consisting of all permutations of length N of D digits ; Initialize set to see if all the possible permutations are present in the min length string ; To keep min length string ; Generate the required string ; Iterate over all the possible character ; Append to make a new string ; If the new string is not visited ; Add in set ; Call the dfs function on the last d characters ; Base case ; Append '0' n - 1 times ; Call the DFS Function ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; set < string > visited ; string ans ; void dfs ( string curr , int D ) { for ( int x = 0 ; x < D ; ++ x ) { char chr = x + '0' ; string neighbour = curr + chr ; if ( visited . find ( neighbour ) == visited . end ( ) ) { visited . insert ( neighbour ) ; dfs ( neighbour . substr ( 1 ) , D ) ; ans . push_back ( chr ) ; } } } string reqString ( int N , int D ) { if ( N == 1 && D == 1 ) return "0" ; visited . clear ( ) ; ans . clear ( ) ; string start ; for ( int i = 0 ; i < N - 1 ; i ++ ) start . append ( "0" ) ; dfs ( start , D ) ; ans . append ( start ) ; return ans ; } int main ( ) { int N = 2 ; int D = 2 ; cout << reqString ( N , D ) << ' ' ; return 0 ; }
Check if a string is a scrambled form of another string | C ++ Program to check if a given string is a scrambled form of another string ; Strings of non - equal length cant ' be scramble strings ; Empty strings are scramble strings ; Equal strings are scramble strings ; Check for the condition of anagram ; Check if S2 [ 0. . . i ] is a scrambled string of S1 [ 0. . . i ] and if S2 [ i + 1. . . n ] is a scrambled string of S1 [ i + 1. . . n ] ; Check if S2 [ 0. . . i ] is a scrambled string of S1 [ n - i ... n ] and S2 [ i + 1. . . n ] is a scramble string of S1 [ 0. . . n - i - 1 ] ; If none of the above conditions are satisfied ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isScramble ( string S1 , string S2 ) { if ( S1 . length ( ) != S2 . length ( ) ) { return false ; } int n = S1 . length ( ) ; if ( n == 0 ) { return true ; } if ( S1 == S2 ) { return true ; } string copy_S1 = S1 , copy_S2 = S2 ; sort ( copy_S1 . begin ( ) , copy_S1 . end ( ) ) ; sort ( copy_S2 . begin ( ) , copy_S2 . end ( ) ) ; if ( copy_S1 != copy_S2 ) { return false ; } for ( int i = 1 ; i < n ; i ++ ) { if ( isScramble ( S1 . substr ( 0 , i ) , S2 . substr ( 0 , i ) ) && isScramble ( S1 . substr ( i , n - i ) , S2 . substr ( i , n - i ) ) ) { return true ; } if ( isScramble ( S1 . substr ( 0 , i ) , S2 . substr ( n - i , i ) ) && isScramble ( S1 . substr ( i , n - i ) , S2 . substr ( 0 , n - i ) ) ) { return true ; } } return false ; } int main ( ) { string S1 = " coder " ; string S2 = " ocred " ; if ( isScramble ( S1 , S2 ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }
Smallest number possible by swapping adjacent even odd pairs | C ++ Program to find the smallest number possible by swapping adjacent digits of different parity ; Function to return the smallest number possible ; Arrays to store odd and even digits in the order of their appearance in the given string ; Insert the odd and even digits ; pointer to odd digit ; pointer to even digit ; In case number of even and odd digits are not equal If odd digits are remaining ; If even digits are remaining ; Removal of leading 0 's ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; string findAns ( string s ) { int digit ; vector < int > odd ; vector < int > even ; for ( auto c : s ) { digit = c - '0' ; if ( digit & 1 ) odd . push_back ( digit ) ; else even . push_back ( digit ) ; } int i = 0 ; int j = 0 ; string ans = " " ; while ( i < odd . size ( ) and j < even . size ( ) ) { if ( odd [ i ] < even [ j ] ) ans += ( char ) ( odd [ i ++ ] + '0' ) ; else ans += ( char ) ( even [ j ++ ] + '0' ) ; } while ( i < odd . size ( ) ) ans += ( char ) ( odd [ i ++ ] + '0' ) ; while ( j < even . size ( ) ) ans += ( char ) ( even [ j ++ ] + '0' ) ; while ( ans [ 0 ] == '0' ) { ans . erase ( ans . begin ( ) ) ; } return ans ; } int main ( ) { string s = "894687536" ; cout << findAns ( s ) ; return 0 ; }
Program to Convert BCD number into Decimal number | C ++ code to convert BCD to its decimal number ( base 10 ) . ; Function to convert BCD to Decimal ; Iterating through the bits backwards ; Forming the equivalent digit ( 0 to 9 ) from the group of 4. ; Reinitialize all variables and compute the number . ; update the answer ; Reverse the number formed . ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int bcdToDecimal ( string s ) { int len = s . length ( ) , check = 0 , check0 = 0 ; int num = 0 , sum = 0 , mul = 1 , rev = 0 ; for ( int i = len - 1 ; i >= 0 ; i -- ) { sum += ( s [ i ] - '0' ) * mul ; mul *= 2 ; check ++ ; if ( check == 4 i == 0 ) { if ( sum == 0 && check0 == 0 ) { num = 1 ; check0 = 1 ; } else { num = num * 10 + sum ; } check = 0 ; sum = 0 ; mul = 1 ; } } while ( num > 0 ) { rev = rev * 10 + ( num % 10 ) ; num /= 10 ; } if ( check0 == 1 ) return rev - 1 ; return rev ; } int main ( ) { string s = "100000101000" ; cout << bcdToDecimal ( s ) ; return 0 ; }
Find Count of Single Valued Subtrees | C ++ program to find count of single valued subtrees ; A Tree node ; Utility function to create a new node ; This function increments count by number of single valued subtrees under root . It returns true if subtree under root is Singly , else false . ; Return false to indicate NULL ; Recursively count in left and right subtrees also ; If any of the subtrees is not singly , then this cannot be singly . ; If left subtree is singly and non - empty , but data doesn 't match ; Same for right subtree ; If none of the above conditions is true , then tree rooted under root is single valued , increment count and return true . ; This function mainly calls countSingleRec ( ) after initializing count as 0 ; Initialize result ; Recursive function to count ; Driver program to test ; Let us construct the below tree 5 / \ 4 5 / \ \ 4 4 5
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; Node * newNode ( int data ) { Node * temp = new Node ; temp -> data = data ; temp -> left = temp -> right = NULL ; return ( temp ) ; } bool countSingleRec ( Node * root , int & count ) { if ( root == NULL ) return true ; bool left = countSingleRec ( root -> left , count ) ; bool right = countSingleRec ( root -> right , count ) ; if ( left == false right == false ) return false ; if ( root -> left && root -> data != root -> left -> data ) return false ; if ( root -> right && root -> data != root -> right -> data ) return false ; count ++ ; return true ; } int countSingle ( Node * root ) { int count = 0 ; countSingleRec ( root , count ) ; return count ; } int main ( ) { Node * root = newNode ( 5 ) ; root -> left = newNode ( 4 ) ; root -> right = newNode ( 5 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 4 ) ; root -> right -> right = newNode ( 5 ) ; cout << " Count ▁ of ▁ Single ▁ Valued ▁ Subtrees ▁ is ▁ " << countSingle ( root ) ; return 0 ; }
Count minimum swap to make string palindrome | C ++ program to Count minimum swap to make string palindrome ; Function to Count minimum swap ; calculate length of string as n ; counter to count minimum swap ; A loop which run till mid of string ; Left pointer ; Right pointer ; A loop which run from right pointer towards left pointer ; if both char same then break the loop . If not , then we have to move right pointer to one position left ; If both pointers are at same position , it denotes that we don 't have sufficient characters  to make palindrome string ; Driver code ; Function calling
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countSwap ( string s ) { int n = s . length ( ) ; int count = 0 ; for ( int i = 0 ; i < n / 2 ; i ++ ) { int left = i ; int right = n - left - 1 ; while ( left < right ) { if ( s [ left ] == s [ right ] ) { break ; } else { right -- ; } } if ( left == right ) { return -1 ; } for ( int j = right ; j < n - left - 1 ; j ++ ) { swap ( s [ j ] , s [ j + 1 ] ) ; count ++ ; } } return count ; } int main ( ) { string s = " geeksfgeeks " ; int ans1 = countSwap ( s ) ; reverse ( s . begin ( ) , s . end ( ) ) ; int ans2 = countSwap ( s ) ; cout << max ( ans1 , ans2 ) ; return 0 ; }
Bitwise XOR of a Binary array | C ++ implementation of the approach ; Function to return the bitwise XOR of all the binary strings ; Get max size and reverse each string Since we have to perform XOR operation on bits from right to left Reversing the string will make it easier to perform operation from left to right ; Add 0 s to the end of strings if needed ; Perform XOR operation on each bit ; Reverse the resultant string to get the final string ; Return the final string ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void strBitwiseXOR ( string * arr , int n ) { string result ; int max_len = INT_MIN ; for ( int i = 0 ; i < n ; i ++ ) { max_len = max ( max_len , ( int ) arr [ i ] . size ( ) ) ; reverse ( arr [ i ] . begin ( ) , arr [ i ] . end ( ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { string s ; for ( int j = 0 ; j < max_len - arr [ i ] . size ( ) ; j ++ ) s += '0' ; arr [ i ] = arr [ i ] + s ; } for ( int i = 0 ; i < max_len ; i ++ ) { int pres_bit = 0 ; for ( int j = 0 ; j < n ; j ++ ) pres_bit = pres_bit ^ ( arr [ j ] [ i ] - '0' ) ; result += ( pres_bit + '0' ) ; } reverse ( result . begin ( ) , result . end ( ) ) ; cout << result ; } int main ( ) { string arr [ ] = { "1000" , "10001" , "0011" } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; strBitwiseXOR ( arr , n ) ; return 0 ; }
Count of sticks required to represent the given string | C ++ implementation of the above approach ; stick [ ] stores the count of matchsticks required to represent the alphabets ; number [ ] stores the count of matchsticks required to represent the numerals ; Function that return the count of sticks required to represent the given string ; For every char of the given string ; Add the count of sticks required to represent the current character ; Driver code ; Function call to find the count of matchsticks
#include <bits/stdc++.h> NEW_LINE using namespace std ; int sticks [ ] = { 6 , 7 , 4 , 6 , 5 , 4 , 6 , 5 , 2 , 4 , 4 , 3 , 6 , 6 , 6 , 5 , 7 , 6 , 5 , 3 , 5 , 4 , 6 , 4 , 3 , 4 } ; int number [ ] = { 6 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 } ; int countSticks ( string str ) { int cnt = 0 ; for ( int i = 0 ; str [ i ] ; i ++ ) { char ch = str [ i ] ; if ( ch >= ' A ' && ch <= ' Z ' ) { cnt += sticks [ ch - ' A ' ] ; } else { cnt += number [ ch - '0' ] ; } } return cnt ; } int main ( ) { string str = " GEEKSFORGEEKS " ; cout << countSticks ( str ) ; return 0 ; }
CamelCase Pattern Matching |  ; Concatenating all array elements using Aggregate function of LINQ putting semicolon as delimiter after each element ; Map to store the hashing of each words with every uppercase letter found ; temporary Variables ; Traversing through concatenated String ; Identifying if the current Character is CamelCase If so , then adding to map accordingly ; If pattern matches then print the corresponding mapped words ; If delimiter has reached then reseting temporary string also incrementing word position value ; If pattern matches then print the corresponding mapped words ; Driver code ; Array of words ; Pattern to be found ; Function call to find the words that match to the given pattern
#include <bits/stdc++.h> NEW_LINE using namespace std ; void PrintMatchingCamelCase ( vector < string > arr , string pattern ) { string cctdString = " " ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { cctdString += arr [ i ] ; if ( i != arr . size ( ) - 1 ) cctdString . push_back ( ' ; ' ) ; } unordered_map < string , vector < string > > maps ; int charPos = 0 ; int wordPos = 0 ; string strr = " " ; for ( ; charPos < cctdString . length ( ) ; charPos ++ ) { if ( cctdString [ charPos ] >= ' A ' && cctdString [ charPos ] <= ' Z ' ) { strr += cctdString [ charPos ] ; if ( maps . find ( strr ) != maps . end ( ) ) { vector < string > temp ; temp . insert ( temp . end ( ) , maps [ strr ] . begin ( ) , maps [ strr ] . end ( ) ) ; temp . push_back ( arr [ wordPos ] ) ; maps [ strr ] = temp ; } else { vector < string > vec = { arr [ wordPos ] } ; maps [ strr ] = vec ; } } else if ( cctdString [ charPos ] == ' ; ' ) { wordPos ++ ; strr = " " ; } } if ( maps . find ( pattern ) != maps . end ( ) ) { for ( int i = 0 ; i < maps [ pattern ] . size ( ) ; i ++ ) { cout << maps [ pattern ] [ i ] << endl ; } } else { cout << " No ▁ Match ▁ Found " << endl ; } } int main ( ) { vector < string > arr = { " Hi " , " Hello " , " HelloWorld " , " HiTech " , " HiGeek " , " HiTechWorld " , " HiTechCity " , " HiTechLab " } ; string pattern = " HT " ; PrintMatchingCamelCase ( arr , pattern ) ; }