Skip to content

Instantly share code, notes, and snippets.

@knuu
Created December 24, 2015 17:18
Show Gist options
  • Save knuu/e1e1df71c0ebf675536e to your computer and use it in GitHub Desktop.
Save knuu/e1e1df71c0ebf675536e to your computer and use it in GitHub Desktop.
SRM663 div.1 300 ABBADiv1
class ABBADiv1:
def canObtain(self, initial, target):
def dfs(s):
if len(s) == len(target):
return s == target
if s not in target and s not in rev_target:
return False
return dfs(s + 'A') or dfs((s + 'B')[::-1])
rev_target = target[::-1]
return "Possible" if dfs(initial) else "Impossible"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment