Last active
December 11, 2020 03:28
-
-
Save bhbmaster/b536960bdd0296769e1acd956806a686 to your computer and use it in GitHub Desktop.
Google Interview Question 2 - Remove duplicates. Uniq on a 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
# | |
# | |
# example input: aaaabbcaaa | |
# output: abca | |
# | |
# | |
# req: python 3.5+ | |
# | |
# | |
def solve(string): | |
ans="" | |
cont=False | |
oldval="BLAH" | |
for i,val in enumerate(string): | |
# print(f"{i} {val}") | |
if val==oldval: | |
cont=True | |
else: | |
ans += val | |
cont=False | |
oldval=val | |
print(ans) | |
solve("abc") # abc | |
solve("aaaabbcaaa") # abca | |
solve("abczzz") # abcz | |
solve("assssssssssswassssddddddddssss") | |
solve("kooooooooossstttttttttttttttttiaaaaaaaaaa asdfasdf") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment