manjunath.ns

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
import java.util.ArrayList;
- manjunath.ns April 09, 2015public class TestBuildHierachy {
/**
* @param args
*/
public static void main(String[] args) {
HashMap < String, String > employees = new HashMap < String, String > ();
employees.put("A", "C");
employees.put("B", "C");
employees.put("C", "F");
employees.put("D", "E");
employees.put("E", "F");
employees.put("F", "F");
buildHierachy(employees);
}
public static void buildHierachy(HashMap < String, String > employees) {
HashMap < String, Manager > managerMap = new HashMap < String, Manager > ();
Manager ceo = null;
for (String manager: employees.values()) {
if (!managerMap.containsKey(manager)) {
managerMap.put(manager, new Manager(manager));
}
}
for (String employee: employees.keySet()) {
String managerName = employees.get(employee);
if (employee.equals(managerName)) {
ceo = managerMap.get(managerName);
} else if (managerMap.containsKey(employee)) {
managerMap.get(managerName).addChildren(
managerMap.get(employee));
} else {
Employee emp = new Employee(employee);
managerMap.get(managerName).addChildren(emp);
}
}
if (ceo != null) {
ceo.printDepth(new Integer(0));
}
}
}
class Manager extends Employee {
List < Employee > children = new ArrayList < Employee > ();
public Manager(String name) {
super(name);
}
public void addChildren(Employee ele) {
children.add(ele);
}
public int printDepth(Integer depth) {
for (Employee emp: children) {
depth += emp.printDepth(new Integer(0));
}
System.out.println(name + " : " + depth);
return depth + 1;
}
}
class Employee {
String name;
public Employee(String name) {
this.name = name;
}
public int printDepth(Integer depth) {
System.out.println(name + " : " + 0);
return 1;
}
}