We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def superReducedString(s):
# Write your code here
stack = []
for char in s:
if stack and stack[-1] == char:
stack.pop()
else:
stack.append(char)
reduced_string = ''.join(stack)
return reduced_string if reduced_string else 'Empty String'
if name == 'main':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
s = input()
result = superReducedString(s)
fptr.write(result + '\n')
fptr.close()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Super Reduced String
You are viewing a single comment's thread. Return to all comments →
!/bin/python3
def superReducedString(s): # Write your code here stack = [] for char in s: if stack and stack[-1] == char: stack.pop() else: stack.append(char) reduced_string = ''.join(stack) return reduced_string if reduced_string else 'Empty String'
if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')