Created
August 13, 2015 06:54
-
-
Save GnsP/c73bd7b12c195ea0d79d to your computer and use it in GitHub Desktop.
zomato_largestST.py
This file contains hidden or 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
| 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