Created
October 30, 2012 19:09
-
-
Save SudhagarS/3982319 to your computer and use it in GitHub Desktop.
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 reduce(s): | |
global value, minimum | |
l = len(s) | |
minimum = l | |
if l == 1: | |
value = 1 | |
return True | |
elif l == 2 and s[0] == s[1]: | |
value = 2 | |
return True | |
for i in range(l - 1): | |
if s[i] != s[i + 1]: | |
cat = s[0:i] + (set("abc") - set(s[i:i + 2])).pop() + s[i + 2:l] | |
if reduce(cat): | |
minimum = min(value, minimum) | |
return True | |
return False | |
minimum, value, N = 1, 1, int(raw_input()) | |
for _ in xrange(N): | |
reduce(raw_input()) | |
print minimum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment