Given (i) a non-empty binary search tree with double values (e.g. 3.5) in each node and (ii) a key value K. Write a method to find the closest value to K.
Code input/output:
printing inorder of BST:
3.3 3.49 3.51 3.52 3.55 3.56 3.57 3.59 3.62 3.65
Closest to 3.559: 3.56
Approach:
Full Code:
No comments:
Post a Comment