Skip to content

Instantly share code, notes, and snippets.

@GnsP
Created August 13, 2015 06:54
Show Gist options
  • Select an option

  • Save GnsP/c73bd7b12c195ea0d79d to your computer and use it in GitHub Desktop.

Select an option

Save GnsP/c73bd7b12c195ea0d79d to your computer and use it in GitHub Desktop.
zomato_largestST.py
tree = [0 for x in range(1000)]
def countNodes(root):
pass
def addChildren(children, parent):
tree[parent<<1] = children[0]
tree[parent<<1|1] = children[1]
def isBST(root):
return tree[root] > tree[root<<1] and tree[root] < tree[root<<1|1] and isBST(root<<1) and isBST(root<<1|1)
def findLargest(root):
if isBST(root):
return root
c_l = 0
c_r = 0
l = -1
r = -1
if isBST(root<<1):
l = findLargest(root<<1))
c_l = countNodes(l)
if isBST(root<<1|1):
r = findLargest(root<<1|1))
c_r = countNodes(r)
if cl > cr:
return l
return r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment