-
Notifications
You must be signed in to change notification settings - Fork 32
/
57_BinarySearchTreeLCA.cpp
25 lines (17 loc) · 1003 Bytes
/
57_BinarySearchTreeLCA.cpp
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
// For this challenge you will attempt to find the lowest common ancestor of a binary search tree.
/*
have the function BinarySearchTreeLCA(strArr) take the array of strings stored in strArr, which will contain 3 elements: the first element will be a binary search tree with all unique values in a preorder traversal array, the second and third elements will be two different values, and your goal is to find the lowest common ancestor of these two values. For example: if strArr is ["[10, 5, 1, 7, 40, 50]", "1", "7"] then this tree looks like the following:
For the input above, your program should return 5 because that is the value of the node that is the LCA of the two nodes with values 1 and 7. You can assume the two nodes you are searching for in the tree will exist somewhere in the tree.
*/
#include <iostream>
#include <string>
using namespace std;
string BinarySearchTreeLCA(string strArr[])
{
}
int main()
{
string A[] = {};
cout << BinarySearchTreeLCA(A) << endl;
return 0;
}