Handle Score
@Ibrahim Nash 6560
@blackshadows 6400
@mb1973 5777
@Quandray 5271
@akhayrutdinov 5111
@saiujwal13083 5074
@kirtidee18 4356
@sanjay05 3762
@mantu_singh 3638
@gfgaccount 3601
@marius_valentin_dragoi 3525
Complete Leaderboard
Remaining String
Easy Accuracy: 27.84% Submissions: 2739 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

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