This is a verified interview question from Sprinklr. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Company Hierarchy Queries - Sprinklr Online Assessment DTU" covers key patterns like Trees.
"### Problem A company has N employees numbered from 1 to N. Employee 1 is the CEO. For every employee i (2 ≤ i ≤ N), you are given their direct manager. The hierarchy forms a rooted tree. You have to answer Q independent queries. Each query contains two integers: X — an employee. K — number of levels to move upward. Return the employee that is exactly K levels above X. If such an employee does not exist, print -1. Input The first line contains N Q The second line contains N−1 integers P2 P3 ... PN where Pi is the direct manager of employee i. Each of the next Q lines contains X K Output For every query print the answer on a new line. "
Join thousands of developers practicing for Sprinklr.