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 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.
- 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
- Decrypt a string encrypted by repeating i-th character i times
- Check if max occurring character of one string appears same no. of times in other
- Print last character of each word in a string
- Print the first and last character of each word in a String
- Print Kth character in sorted concatenated substrings of a string
- Print the string by ignoring alternate occurrences of any character
- 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