Given a string, a character, and a count, the task is to print the string after the specified character has occurred count number of times.Print “Empty string” in case of any unsatisfying conditions.(Given character is not present, or present but less than given count, or given count completes on last index). If given count is 0, then given character doesn’t matter, just print the whole string.
Input : str = "This is demo string" char = i, count = 3 Output : ng Input : str = "geeksforgeeks" char = e, count = 2 Output : ksforgeeks
Asked in: Oracle
1- Start traversing the string.
- Increment occ_count if current char is equal to given char.
- Get out of the loop, if occ_count becomes equal to given count.
2- Print the string after the index till the string gets traversed in the loop.
3- If index has reached to the last, then print “Empty string”.
ks for geeks
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.
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.
- Replace every character of string by character whose ASCII value is K times more than it
- Queries to print the character that occurs the maximum number of times in a given range
- Encrypt a string by repeating i-th character i times
- Check if max occurring character of one string appears same no. of times in other
- Decrypt a string encrypted by repeating i-th character i times
- Print last character of each word in a string
- Print the first and last character of each word in a String
- Print the string by ignoring alternate occurrences of any character
- Print Kth character in sorted concatenated substrings of a string
- Number of sub-strings that contain the given character exactly k times
- Count of substrings which contains a given character K times
- Longest subsequence where every character appears at-least k times
- Longest subsequence where each character occurs at least k times
- Count substrings with each character occurring at most k times
- Lexicographically largest subsequence such that every character occurs at least k times
- 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
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Map every character of one string to another such that all occurrences are mapped to the same character
- String obtained by reversing and complementing a Binary string K times