Created
April 22, 2018 00:23
-
-
Save jsgoller1/e45aacff0848930e40bc00cac59a653e to your computer and use it in GitHub Desktop.
HackerRank: "Super Reduced String"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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