Missing characters to make a string Pangram
Pangram is a sentence containing every letter in the English alphabet. Given a string, find all characters that are missing from the string, i.e., the characters that can make string a Pangram. We need to print output in alphabetic order.
Examples:
Input : welcome to geeksforgeeks Output : abdhijnpquvxyz Input : The quick brown fox jumps Output : adglvyz
We have discussed Pangram Checking. The idea is similar, we traverse given string and mark all visited characters. At the end, we print all those characters which are not visited.
Lowercase and Uppercase character are considered same.
// C++ program to find characters that needs // to be added to make Pangram #include<bits/stdc++.h> using namespace std; const int MAX_CHAR = 26; // Returns characters that needs to be added // to make str string missingChars(string str) { // A boolean array to store characters // present in string. bool present[MAX_CHAR] = {false}; // Traverse string and mark characters // present in string. for (int i=0; i<str.length(); i++) { if (str[i] >= 'a' && str[i] <= 'z') present[str[i]-'a'] = true; else if (str[i] >= 'A' && str[i] <= 'Z') present[str[i]-'A'] = true; } // Store missing characters in alphabetic // order. string res = ""; for (int i=0; i<MAX_CHAR; i++) if (present[i] == false) res.push_back((char)(i+'a')); return res; } // Driver program int main() { string str = "The quick brown fox jumps " "over the dog"; cout << missingChars(str); return 0; } |
Output:
alyz
Time Complexity : O(n)
Auxiliary Space : O(1)
This article is contributed by Pramod Kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Recommended Posts:
- Make lexicographically smallest palindrome by substituting missing characters
- Min flips of continuous characters to make all characters same in a string
- Make a string from another by deletion and rearrangement of characters
- Minimum characters to be added at front to make string palindrome
- Minimum replacements to make adjacent characters unequal in a ternary string
- Minimum replacements to make adjacent characters unequal in a ternary string | Set-2
- Minimum number of characters to be removed to make a binary string alternate
- Check if a String can be converted to Pangram in K changes
- Python program to check if given string is pangram
- Replace minimal number of characters to make all characters pair wise distinct
- Count the nodes of the tree which make a pangram when concatenated with the sub-tree nodes
- Permutation of a string with maximum number of characters greater than its adjacent characters
- String with k distinct characters and no same characters adjacent
- Minimum operations to make frequency of all characters equal K
- Print the arranged positions of characters to make palindrome



