Created
October 6, 2019 00:47
-
-
Save sheldonrobinson/ff4ccef8fc5211d3c5d4c58a2d3e03aa to your computer and use it in GitHub Desktop.
CodeSignal Solution findProfession
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 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