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)
Constraints:
1 <= |S| <= 10^{5}
Assume upper case and lower case
alphabets as different

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3

class Solution:

	def printString(self, S, ch, count):

		# code here

Solutions:
import re

class Solution:

	def printString(self, S, ch, count):
		l = len(re.findall(ch, S))
		if count == 0:
			return S
		if l >= count:
			res = list(re.finditer(ch, S))[count - 1].end()
			if res == len(S):
				return 'Empty string'
			return S[res:]
		else:
			return 'Empty string'


class Solution:

	def printString(self, s, ch, count):
		k = 0
		if count == 0:
			return s
		for i in range(len(s)):
			if s[i] == ch:
				k += 1
			if k == count and i < len(s) - 1:
				return s[i + 1:]
		return 'Empty string'


class Solution:

	def printString(self, S, ch, count):
		c = 0
		a = -1
		n = len(S)
		if count == 0:
			return S
		for i in range(n):
			if S[i] == ch:
				c += 1
			if c == count:
				a = i
				break
		if a == -1:
			return 'Empty string'
		else:
			s = ''
			flag = 0
			for i in range(a + 1, n):
				s = s + S[i]
				flag = 1
			if flag == 1:
				return s
			else:
				return 'Empty string'


class Solution:

	def printString(self, S, ch, count):
		if count == 0:
			return S
		l = len(S)
		c = 0
		for i in range(l):
			if S[i] == ch:
				c += 1
			if c == count and i < l - 1:
				return S[i + 1:]
		return 'Empty string'


class Solution:

	def printString(self, S, ch, count):
		c = 0
		j = -1
		for i in range(0, len(S)):
			if S[i] == ch:
				c += 1
			if c == count:
				j = i
				break
		if count == 0:
			return S
		elif c == count and j != len(S) - 1:
			return S[j + 1:len(S)]
		else:
			return 'Empty string'


class Solution:

	def printString(self, S, ch, count):
		s = ''
		for i in range(len(S)):
			if count <= 0:
				s += S[i]
			if S[i] == ch:
				count -= 1
		if len(s) == 0:
			return 'Empty string'
		else:
			return s


class Solution:

	def printString(self, S, ch, count):
		res = ''
		for each in S:
			if count == 0:
				res += each
			if each == ch and count >= 1:
				count -= 1
		if res == '':
			return 'Empty string'
		else:
			return res


class Solution:

	def printString(self, S, ch, count):
		(i, cnt) = (0, 0)
		if count == 0:
			return S
		for i in range(len(S)):
			if S[i] == ch:
				cnt += 1
			if cnt == count:
				break
		if cnt < count or S[i + 1:] == '':
			return 'Empty string'
		if cnt == count:
			return S[i + 1:]


class Solution:

	def printString(self, S, ch, count):
		result = 'Empty string'
		number = 0
		if count == 0 and ch in S:
			return S
		if len(S) == 0 or len(S) == 1:
			return result
		if ch not in S:
			return result
		for i in range(int(len(S))):
			if S[i] == ch:
				number += 1
				if number == int(count):
					result = S[i + 1:]
					if len(result) == 0:
						result = 'Empty string'
		return result


class Solution:

	def printString(self, S, ch, count):
		if count == 0:
			return S
		c = 0
		ss = ''
		for i in range(len(S)):
			if S[i] == ch:
				c += 1
			if c == count:
				if i + 1 < len(S):
					for i in range(i + 1, len(S)):
						ss += S[i]
				break
		if ss == '':
			return 'Empty string'
		return ss


class Solution:

	def printString(self, S, ch, count):
		if count == 0:
			return S
		if S.count(ch) < count:
			return 'Empty string'
		else:
			count1 = 0
			for (num, i) in enumerate(S):
				if i == ch:
					count1 += 1
				if count1 == count:
					break
			if len(S[num + 1:]) == 0:
				return 'Empty string'
			return S[num + 1:]


class Solution:

	def printString(self, S, ch, count):
		if count == 0:
			return S
		co = 0
		ans = []
		a = list(S)
		for i in range(len(S)):
			if a[i] == ch:
				co += 1
			if co == count:
				ans += a[i + 1:]
				break
		ans = ''.join(ans)
		if ans == '':
			return 'Empty string'
		else:
			return ans


class Solution:

	def printString(self, s, ch, count):
		a = ''
		x = 0
		m = 0
		if count == 0:
			return s
		for i in range(len(s)):
			if s[i] == ch:
				x += 1
				if x == count:
					m = i
					break
		for i in range(i + 1, len(s)):
			a += s[i]
		if len(a) == 0:
			return 'Empty string'
		else:
			return a


class Solution:

	def printString(self, S, ch, count):
		ans = None
		var = 0
		if ch not in S:
			ans = ''
		if count == 0:
			ans = S
		else:
			lst = list()
			for i in range(len(S)):
				if S[i] == ch:
					var += 1
					if var == count:
						ans = S[i + 1:]
						break
				else:
					continue
			else:
				ans = ''
		if ans == '':
			ans = 'Empty string'
		return ans


class Solution:

	def printString(self, S, ch, count):
		if count == 0:
			return S
		indices = [i for i in range(len(S)) if S[i] == ch]
		if len(indices) < count:
			return 'Empty string'
		index = indices[count - 1]
		if index + 1 < len(S):
			remaining_str = S[index + 1:]
			return remaining_str
		else:
			return 'Empty string'


class Solution:

	def printString(self, S, ch, count):
		if not count:
			return S
		if S.count(ch) < count:
			return 'Empty string'
		p = {}
		for i in range(len(s)):
			if S[i] == ch:
				count -= 1
			if not count:
				if i == len(S) - 1:
					return 'Empty string'
				return s[i + 1:]


class Solution:

	def printString(self, S, ch, count):
		i = 0
		ans = 'Empty string'
		while i < len(S) and count > 0:
			if S[i] == ch:
				count -= 1
			i += 1
		if count > 0 or i == len(S):
			return ans
		return S[i:]


class Solution:

	def printString(self, S, ch, count):
		z = 0
		k = 0
		if ch in S and count == 0:
			return S
		while z < len(S):
			if S[z] == ch:
				k += 1
			if k == count and z != len(S) - 1:
				return S[z + 1:]
			z += 1
		return 'Empty string'


class Solution:

	def printString(self, S, ch, count):
		n = len(S)
		l = list(S)
		if l.count(ch) < count:
			return 'Empty string'
		if count == 0:
			return S
		else:
			count1 = 0
			for i in range(n):
				if S[i] == ch:
					count1 += 1
				if count1 == count and i != n - 1:
					p = S[i + 1:]
					return p
				if i == n - 1 and count1 == count:
					return 'Empty string'


class Solution:

	def printString(self, S, ch, count):
		if count == 0:
			return S
		if s[0] == ch and count == 1:
			return S[1:]
		ans = ''
		c = 0
		for i in S:
			if c >= count:
				ans += i
			if i == ch:
				c += 1
		if ans == '':
			return 'Empty string'
		return ans


class Solution:

	def printString(self, S, ch, count):
		if count == 0:
			return S
		c = 0
		ii = 0
		for (i, e) in enumerate(S, start=1):
			if c != count:
				if e == ch:
					c += 1
					ii = i
			else:
				res = S[ii:]
				return res
		return 'Empty string'


class Solution:

	def printString(self, s, c, count):
		if s.count(c) < count:
			return 'Empty string'
		for i in range(count):
			if s.index(c) + 1 < len(s):
				s = s[s.index(c) + 1:]
			else:
				return 'Empty string'
		return s


class Solution:

	def printString(self, S, ch, count):
		if count == 0:
			return S
		else:
			c = 0
			z = 0
			ans = ''
			for i in S:
				z += 1
				if i == ch:
					c += 1
				if c == count:
					break
			if z == len(S):
				return 'Empty string'
			else:
				res = S[z:]
				return res


class Solution:

	def printString(self, s, ch, c):
		if c == 0:
			return s
		x = 0
		y = ''
		for i in range(len(s)):
			if s[i] == ch:
				x += 1
				if x == c:
					y = s[i + 1:]
				else:
					pass
			else:
				pass
		if len(y) == 0:
			return 'Empty string'
		else:
			return y


class Solution:

	def printString(self, S, ch, count):
		index = -1
		CurCount = 0
		if count == 0:
			return S
		for i in range(len(S)):
			if S[i] == ch:
				index = i
				CurCount += 1
				if CurCount == count:
					break
		return S[index + 1:] if CurCount == count and (S[index + 1:] if count != 0 else True) else 'Empty string'


class Solution:

	def printString(self, S, ch, count):
		res = str()
		curr = 0
		if count == 0:
			return S
		for i in S:
			if i == ch:
				curr += 1
			if curr >= count:
				res += i
		if curr < count or len(res) == 1:
			return 'Empty string'
		return res[1:]


class Solution:

	def printString(self, S, ch, count):
		ct = 0
		x = 'Empty string'
		for i in range(len(S)):
			if S[i] == ch:
				ct = ct + 1
				if ct == count:
					x = S[i + 1:len(S)]
				if len(x) == 0:
					x = 'Empty string'
			if count == 0:
				x = S
		return x


class Solution:

	def printString(self, S, ch, count):
		if count == 0:
			return S
		i = 0
		while i < len(S):
			if S[i] == ch:
				count -= 1
			if count == 0:
				break
			i += 1
		ans = S[i + 1:len(S)]
		return ans if len(ans) != 0 else 'Empty string'


class Solution:

	def printString(self, s, ch, count):
		i = 0
		while i < len(s) and count:
			if s[i] == ch:
				count -= 1
			i += 1
		if i == len(s):
			return 'Empty string'
		return s[i:]


class Solution:

	def printString(self, S, ch, count):
		f = ''.join(ch)
		count1 = 0
		C = ''
		if count == 0:
			return S
		else:
			for a in range(0, len(S)):
				if f == S[a]:
					count1 += 1
				if count1 == count and a != len(S) - 1:
					B = S[a + 1:]
					C = C + B
					break
			if len(C) > 0:
				return C
			elif C == '':
				return 'Empty string'


class Solution:

	def printString(self, s, ch, count):
		if count == 0:
			return s
		ns = ''
		c = 0
		for i in range(0, len(s)):
			if s[i] == ch:
				c += 1
			if c == count:
				break
		else:
			ns = ''
		ns = s[i + 1:]
		return 'Empty string' if ns == '' else ns


class Solution:

	def printString(self, S, ch, count):
		if count == 0:
			return S
		else:
			text = S
			c = count
			cou = 0
			num = 1
			let = ch
			for i in text:
				if i == let:
					cou += 1
				if cou == count:
					break
				num += 1
			li = text[num:]
			if len(li) > 0:
				return li
			else:
				return 'Empty string'


class Solution:

	def printString(self, S, ch, count):
		if count == 0:
			return S
		if ch not in S:
			return 'Empty string'
		if S.count(ch) < count:
			return 'Empty string'
		cnt = 0
		str = ''
		l = len(S)
		j = 0
		for i in range(0, l):
			if cnt != count:
				if S[i] == ch:
					cnt += 1
			else:
				j = i
				break
		if j != 0:
			for i in range(j, l):
				str += S[i]
		else:
			return 'Empty string'
		return str


class Solution:

	def printString(self, S, ch, count):
		if count == 0:
			return S
		init = 0
		p = 0
		for i in range(len(S)):
			if S[i] == ch:
				init += 1
				if init == count and i < len(S) - 1:
					p = 1
					return S[i + 1:]
		if p != 1:
			return 'Empty string'


class Solution:

	def printString(self, S, ch, count):
		ans = ''
		c = 0
		for i in S:
			if c == count:
				ans = ans + i
			elif i == ch:
				c = c + 1
		if len(ans) == 0:
			return 'Empty string'
		return ans


class Solution:

	def printString(self, S, ch, count):
		if count == 0:
			return S
		if S.count(ch) < count or ch not in S:
			return 'Empty string'
		s = list(S)
		i = 0
		a = 0
		while i < len(s):
			if s[i] == ch:
				count -= 1
			if count == 0:
				a = i
				break
			else:
				i += 1
		b = ''
		if a + 1 == len(s):
			return 'Empty string'
		for j in range(a + 1, len(s)):
			b += s[j]
		return b


class Solution:

	def printString(self, s, ch, count):
		if count != 0:
			for i in range(0, len(s) - 1):
				if s[i] == ch and count == 1:
					return s[i + 1:]
					break
				elif s[i] == ch:
					count = count - 1
					continue
				else:
					continue
			return 'Empty string'
			return count
		else:
			return s


class Solution:

	def printString(self, S, ch, count):
		res = ''
		for i in S:
			if i == ch:
				count -= 1
				if count == 0:
					continue
			if count <= 0:
				res += i
		if len(res) == 0:
			return 'Empty string'
		return res


class Solution:

	def printString(self, S, ch, count):
		if S.count(ch) < count:
			return 'Empty string'
		for i in range(count):
			if S.index(ch) == len(S) - 1:
				return 'Empty string'
			S = S[S.index(ch) + 1:]
		return S


class Solution:

	def printString(self, S, ch, count):
		r = ''
		c = 0
		for i in S:
			if c >= count:
				r += i
			if i == ch:
				c += 1
		if not r:
			return 'Empty string'
		return r


class Solution:

	def printString(self, s, ch, count):
		c = 0
		f = False
		k = ''
		for i in range(0, len(s)):
			if c == count:
				k = k + s[i]
				f = True
			elif s[i] == ch and f == False:
				c = c + 1
		if len(k) == 0:
			return 'Empty string'
		return k


class Solution:

	def printString(self, S, ch, count):
		count1 = 0
		k = ''
		flag = 0
		for i in range(len(S)):
			if count1 == count:
				k += S[i]
				flag = 1
			elif S[i] == ch and flag == 0:
				count1 += 1
		if len(k) == 0:
			return 'Empty string'
		return k


class Solution:

	def printString(self, S, ch, count):
		t = ''
		l = []
		s = S.split(ch)
		for i in range(count, len(s)):
			l.append(s[i])
		l = ch.join(l)
		for i in l:
			t += i
		if len(l) == 0:
			return 'Empty string'
		else:
			return t


class Solution:

	def printString(self, S, ch, count):
		occur = 0
		for i in range(len(S)):
			if S[i] == ch:
				occur += 1
			if occur == count:
				break
		if count == 0:
			return S[0:]
		if i + 1 < len(S) and occur == count:
			return S[i + 1:]
		else:
			return 'Empty string'


class Solution:

	def printString(self, S, ch, count):
		cont = 0
		if count == 0:
			return S
		else:
			for i in range(len(S)):
				if S[i] == ch:
					cont += 1
				if cont == count:
					s = S[i + 1:]
					break
		if ch not in S or count > cont or len(s) < 1:
			return 'Empty string'
		else:
			return s