Skip to content

Instantly share code, notes, and snippets.

@jsgoller1
Created April 22, 2018 00:23
Show Gist options
  • Save jsgoller1/e45aacff0848930e40bc00cac59a653e to your computer and use it in GitHub Desktop.
Save jsgoller1/e45aacff0848930e40bc00cac59a653e to your computer and use it in GitHub Desktop.
HackerRank: "Super Reduced String"
#!/bin/python
# Problem statement: https://www.hackerrank.com/challenges/reduced-string/problem
import sys
def remove_first_duplicates(s):
for i in range(0, len(s)-1):
if s[i] == s[i+1]:
return s[:i] + s[i+2:], True
return s, False
def super_reduced_string(s):
# Go through string multiple times, removing
# first instances of duplicates until no duplicates
# remain
removed = True
while (removed):
s, removed = remove_first_duplicates(s)
if s == '':
return "Empty String"
else:
return s
s = raw_input().strip()
result = super_reduced_string(s)
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment