Given a string of both uppercase and lowercase alphabets, the task is to print the string with alternate occurrences of any character dropped(including space and consider upper and lowercase as same).
Input : It is a long day Dear. Output : It sa longdy ear. Print first I and then ignore next i. Similarly print first space then ignore next space. Input : Geeks for geeks Output : Geks fore
Asked in: Microsoft
As we have to print characters in alternate manner, so start traversing the string and perform following two steps:-
- Increment the count of occurrence of current character in a hash table.
- Check if the count becomes odd, then print the current character, else not.
Geks fore It sa longdy ear
This article is contributed by Sahil Chhabra. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Map every character of one string to another such that all occurrences are mapped to the same character
- Replace all occurrences of character X with character Y in given string
- Check if two strings are same ignoring their cases
- Rearrange a binary string as alternate x and y occurrences
- Remove all occurrences of a character in a string
- Number of permutations of a string in which all the occurrences of a given character occurs together
- Count occurrences of a character in a repeated string
- Remove all occurrences of a character in a string | Recursive approach
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Longest substring between any pair of occurrences ōf similar characters
- Check if all occurrences of a character appear together
- Minimize ASCII values sum after removing all occurrences of one character
- Find the number of occurrences of a character upto preceding position
- Count occurrences of a string that can be constructed from another given string
- Smallest string obtained by removing all occurrences of 01 and 11 from Binary String
- Print all possible combinations of the string by replacing '$' with any other digit from the string
- String matching with * (that matches with any) in any of the two strings
- Efficiently find first repeated character in a string without using any additional data structure in one traversal
- Maximum number of characters between any two same character in a string
- Check if the frequency of any character is more than half the length of the string