I was asked this question in an interview but was not able to give efficient solution.
Given an employee class
public class Employee {
int e_id;
int manager_id;
String designation;
}
Input will have list of employees like CEO,MD,ED,VP,Manager,Associate in any order. My task was : Given an id of employee, I need to print levels above and below it in sorted order. CEO will have emp_id and manager_id same.
So I have given id of VP [568,33,VP] then I should print
Above levels :
[1,1,CEO]
[222,1,MD]
[33,222,ED]
Below levels :
[435,568,Manager]
[987,435,Assocaite]
So my question is , using java how can you solve it. If any java 8 feature or collection feature which I can use ?