The interface function is given two pointers and the returned value is pointer ,not value. If values of the is repeated, say a extreme case: values are all the same. In general solution, root will be returned which considers only values of p, q not their positions in the BST.So I wonder if pointers should be considered.
You need to lookup what is BST (Binary Search Tree.) If values were repeated it wouldn't be BST, and we would not be able to use the BST properties to solve the problem quicker.