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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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 last character of each word in a string
- Print the first and 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
- Find a string such that every character is lexicographically greater than its immediate next character
- Modify the string such that every character gets replaced with the next character in the keyboard
- Replace every character of string by character whose ASCII value is K times more than it
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Count occurrences of a string that can be constructed from another given string
- Replace every character of a string by a different character
- Replace all occurrences of pi with 3.14 in a given string
- Count of occurrences of a "1(0+)1" pattern in a string