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 email@example.com. 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.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Rearrange a binary string as alternate x and y occurrences
- Map every character of one string to another such that all occurrences are mapped to the same character
- Remove all occurrences of a character in a string
- Count occurrences of a character in a repeated string
- Number of permutations of a string in which all the occurrences of a given character occurs together
- Print the first and last character of each word in a String
- Print last character of each word in a string
- Print the string after the specified character has occurred given no. of times
- Print Kth character in sorted concatenated substrings of a string
- 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
- Replace every character of string by character whose ASCII value is K times more than it
- Modify the string such that every character gets replaced with the next character in the keyboard
- Find a string such that every character is lexicographically greater than its immediate next character