human
Check if a string consisting only of a , b , c can be made empty by removing substring " abc " recursively | Function to check if the given string S can be made empty.
Stores the characters of the string S.
Traverse the given string.
If the character is c.
If stack size is greater than 2.
Pop from the stack.
Top two characters in the stack should be ' b ' and ' a ' respectively.
Otherwise , print No.
If character is ' a ' or ' b ' push to stack.
If stack is empty , then print Yes . Otherwise print No.
Driver code"
Solution in Python:
 ... Can you provide a code to check if a string consisting only of a , b , c can be made empty by removing substring " abc " recursively and the other steps required?
assistant
#Here is code to check if a string consisting only of a , b , c can be made empty by removing substring " abc " recursively and the other steps required.
 def canMadeEmpty ( s , n ) :
	st = [ ]
	for i in range ( n ) :
		if s [ i ] == ' c ' :
			if len ( st ) >= 2 :
				b = st [ - 1 ]
				st . pop ( )
				a = st [ - 1 ]
				st . pop ( )
				if a != ' a ' or b != ' b ' :
					return " No "
			else :
				return " No "
		else :
			st . append ( s [ i ] )
	if len ( st ) == 0 :
		return " Yes "
	else :
		return " No "
s = " aabcbc "
n = len ( s )
print ( canMadeEmpty ( s , n ) )