Can you explain

else part of the explanation is hard to understand can you explain ?

here first we recursively call for left and right part
now check if (l!=-1)
if l==-1 means we don’t get target in left
if l!=-1 means we get our target at l distance from current node

hence if (l!=-1)
we check whether l==k or not if yes then our current node is k distance form target so push_back the root->value to result vector
now also percolatedown(root,k-l-1,target)
and at end return l+1 distance from target;

i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course