forked from adnanaziz/EPIJudge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbst_from_sorted_array.py
31 lines (23 loc) · 1.01 KB
/
bst_from_sorted_array.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import functools
from typing import List, Optional
from bst_node import BstNode
from test_framework import generic_test
from test_framework.binary_tree_utils import (binary_tree_height,
generate_inorder)
from test_framework.test_failure import TestFailure
from test_framework.test_utils import enable_executor_hook
def build_min_height_bst_from_sorted_array(A: List[int]) -> Optional[BstNode]:
# TODO - you fill in here.
return None
@enable_executor_hook
def build_min_height_bst_from_sorted_array_wrapper(executor, A):
result = executor.run(
functools.partial(build_min_height_bst_from_sorted_array, A))
if generate_inorder(result) != A:
raise TestFailure('Result binary tree mismatches input array')
return binary_tree_height(result)
if __name__ == '__main__':
exit(
generic_test.generic_test_main(
'bst_from_sorted_array.py', 'bst_from_sorted_array.tsv',
build_min_height_bst_from_sorted_array_wrapper))