S&P Global interview question

Given a tree, create a function for a getting a sub-tree given P and K.