Interview Question
Applications DevelopersCountry: India
Hash[Dept_Name] = Num_Employees
Hash[Employee_Name]=Dept_Name
Now, search for the Dept_Name with highest Employee Number. Then, return all those employees in the second hash table that work in that department. This is an O(n) approach.
We can maintain a Max_Heap where keys are the Num_Employees and values are Dept_Name and then return all employees that work in the Dept corresponding to the root of the Max_Heap.
select Name from EMPLOYEE where Dept=(select Dept from (select sum(Dept),Dept from EMPLOYEE group by Dept order by 1 desc limit 1));
- AJit A September 19, 2013