3
bool search(TreeNode *root, int target, string &s) {7
if (root->val == target) {11
bool find1 = search(root->left, target, s += 'L'); // search on left side12
if (find1) return true;13
s.pop_back(); // backtracking step15
bool find2 = search(root->right, target, s += 'R'); // search on right side16
if (find2) return true;17
s.pop_back(); // backtracking step21
TreeNode *lca(TreeNode *root, int n1, int n2) {22
if (root == NULL) return NULL;23
if (root->val == n1 or root->val == n2) return root;25
TreeNode *left = lca(root->left, n1, n2);26
TreeNode *right = lca(root->right, n1, n2);28
if (left != NULL && right != NULL) return root;29
if (left) return left;30
if (right) return right;32
return NULL; // not present in tree34
string getDirections(TreeNode *root, int startValue, int destValue) {35
TreeNode *temp = lca(root, startValue, destValue);38
search(temp, startValue, s1);39
search(temp, destValue, s2);