solution to problem of finding kth ancestor and kth sibling