Remaining String
Easy Accuracy: 27.27% Submissions: 3639 Points: 2

Given a string S without spaces, a character ch, and an integer count, the task is to find the string after the specified character has occurred count number of times.

Example 1:

Input:  S = "Thisisdemostring", ch = 'i', 
count = 3
Output: ng
Explanation: Substring of S after the 3rd
occurrence of 'i' is "ng"

Example 2:

Input:  S = "Thisisdemostri", ch = 'i', 
count = 3
Output: Empty string
Explanation: 'i' occurce 3rd time at 
last index

Your Task:
Your task is to complete the function printString() which takes a single, a character, and a count as inputs and returns the string. You need not take any input or print anything.

Note:  “Empty string” should be returned incase of any unsatisfying conditions (Given character is not present, or present but less than given count, or given count completes on the last index). If given count is 0, then given character doesn’t matter, just return the whole string.

Expected Time Complexity: O(|s|)
Expected Auxiliary Space: O(1)

1 <= |S| <= 105
Assume upper case and lower case
alphabets as different

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Remaining String

Output Window