when you're asked for kth ancestor of node V: Store in each node the size of its subtree (in the splay tree not the original tree) Access V Now there should be >= K nodes to the left of node V, go to the left child of V and use sub tree sizes to find kth node from the ...
1 class Solution { 2 public: 3 int rank; 4 int result; 5 6 void help(TreeNode* root, int k){ 7 if(!root) return; 8 9 help(root->left, k); 10 if(++rank == k){ 11 result = root->val; 12 return; 13 } 14 help(root->right, k); 15 } 16 int kthSmallest(TreeNode* ...