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): |
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
# | |
# Binary trees are already defined with this interface: | |
# class Tree(object): | |
# def __init__(self, x): | |
# self.value = x | |
# self.left = None | |
# self.right = None | |
def hasPathWithGivenSum(t, s): | |
if t is None: | |
if s==0: |
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
# | |
# Binary trees are already defined with this interface: | |
# class Tree(object): | |
# def __init__(self, x): | |
# self.value = x | |
# self.left = None | |
# self.right = None | |
def isSubtree(t1, t2): | |
def isEqual(left, right): | |
if left == None and right == None: |
OlderNewer