Skip to content

Instantly share code, notes, and snippets.

@sheldonrobinson
Created October 6, 2019 00:47
Show Gist options
  • Save sheldonrobinson/ff4ccef8fc5211d3c5d4c58a2d3e03aa to your computer and use it in GitHub Desktop.
Save sheldonrobinson/ff4ccef8fc5211d3c5d4c58a2d3e03aa to your computer and use it in GitHub Desktop.
CodeSignal Solution findProfession
def findProfession(level, pos):
# Base case
if (level == 1):
return 'Engineer'
# Recursively find parent's profession. If parent
# is a doctar, this node will be a doctal if it is
# at odd position and an engineer if at even position
if (findProfession(level-1, (pos+1)//2) == 'Doctor'):
if (pos%2):
return 'Doctor'
else:
return 'Engineer'
# If parent is an engineer, then current node will be
# an enginner if at add position and doctor if even
# position.
if(pos%2):
return 'Engineer'
else:
return 'Doctor'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment