Add coding exercises for Facebook interviews
Add attempts at solving coding problems to Briefcase.
This commit is contained in:
parent
d2d772e43e
commit
aa66d9b83d
66 changed files with 2994 additions and 0 deletions
22
scratch/facebook/second-largest-item-in-bst.py
Normal file
22
scratch/facebook/second-largest-item-in-bst.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
from collections import deque
|
||||
from node import Node, tree
|
||||
|
||||
def find_largest(node):
|
||||
while node.right:
|
||||
node = node.right
|
||||
return node.value
|
||||
|
||||
def find_second_largest(node):
|
||||
# parent of the rightmost, when rightmost is leaf
|
||||
# max(rightmost.left)
|
||||
prev = None
|
||||
while node.right:
|
||||
prev = node
|
||||
node = node.right
|
||||
if node.left:
|
||||
return find_largest(node.left)
|
||||
else:
|
||||
return prev.value
|
||||
|
||||
assert find_second_largest(tree) == 72
|
||||
print("Success!")
|
||||
Loading…
Add table
Add a link
Reference in a new issue