Skip to content

Instantly share code, notes, and snippets.

@DaniloOliveira28
Created June 20, 2016 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaniloOliveira28/e9bcb326bf0faa4cc2c17952dc7434ce to your computer and use it in GitHub Desktop.
Save DaniloOliveira28/e9bcb326bf0faa4cc2c17952dc7434ce to your computer and use it in GitHub Desktop.
def n_lower_chars(string):
return sum(1 for c in string if c.islower())
def format_word(word):
if word == word.upper() or word == word.lower():
return 0
M = dict()
M[0] = 0
for i in range(1, len(word)):
if word[i] == word[i].lower():
M[i] = M[i - 1]
elif word[i] == word[i].upper():
M[i] = min(M[i - 1] + 1, n_lower_chars(word[:i]))
return M[len(word) - 1]
if __name__ == "__main__":
print format_word("AaAaAAAaAAAaAAAAAA")
print format_word("AaAaAAAaAAAaAAaaaaaaA")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment