Distance between Nodes of BST

Given a binary search tree of integers A.

Return the distance between two nodes with given two keys B and C. It may be assumed that both keys exist in BST.

Note: Distance between two nodes is number of edges between them.


1 <= Number of nodes in binary tree <= 1000000
0 <= node values <= 10^9 

For Example

Input 1:
    A  =    5
          /   \
         2    8
        / \  / \
       1   4 6  11
    B = 2
    C = 11
Output 1:
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Distance between Nodes of BST on Interview Code Editor
Sign Up
to access hints and editorial solutions for Distance between Nodes of BST


Click here to start solving coding interview questions