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.
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.
- 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
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- 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
- Encrypt a string by repeating i-th character i times
- Minimum number of times A has to be repeated such that B is a substring of it
- Replace all occurrences of character X with character Y in given string
- Number of sub-strings that contain the given character exactly k times
- Count of substrings which contains a given character K times
- Minimum sum of squares of character counts in a given string after removing k characters
- Construct a string that has exactly K subsequences from given string
- Reverse substrings of given string according to specified array indices
- Find a string such that every character is lexicographically greater than its immediate next character
- Replace every character of a string by a different character
- Map every character of one string to another such that all occurrences are mapped to the same character
- Modify the string such that every character gets replaced with the next character in the keyboard
- Count of substrings having the most frequent character in the string as first character
- NFA to accept strings that has atleast one character occurring in a multiple of 3
- Print string after removing all (“10” or “01”) from the binary string