Last active
July 12, 2020 14:19
-
-
Save garyshort/259feb55840b5f9c17021d60f5c0bd17 to your computer and use it in GitHub Desktop.
Demo of NationWord Test
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
def number_of_a_additions(aString): | |
# Fail fast | |
if 'aaa' in aString: | |
return -1 | |
if aString == 'aa': | |
return 0 | |
# For any string of n chars long, return | |
# (2(number of chars that aren't 'a') +2) - count('a') | |
not_as = [c for c in aString if c != 'a'] | |
return ((len(not_as) * 2) + 2) - aString.count('a') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment