Mid/Senior

Manager of the Largest Department

You are given an employees table represented as a 2D array of strings, where each row is employees[i] = [emp_id, emp_name, dep_id, position].

A department's size is the total number of employees whose dep_id belongs to that department. The largest department is any department with the maximum size among all departments.

Return the names of all employees whose position is "Manager" and whose dep_id belongs to a largest department. If multiple departments are tied for the largest size, include managers from all tied departments. The answer may be returned in any order.

Example 1
Inputemployees = [["1","Alice","101","Manager"],["2","Bob","101","Engineer"],["3","Charlie","102","Manager"],["4","David","102","Engineer"],["5","Eve","102","Engineer"]]
Output["Charlie"]
Department 102 has 3 employees, which is more than department 101, so its manager Charlie is returned.
Example 2
Inputemployees = [["1","Maya","10","Manager"],["2","Noah","10","Engineer"],["3","Liam","20","Manager"],["4","Olivia","20","Analyst"],["5","Emma","30","Manager"]]
Output["Maya","Liam"]
Departments 10 and 20 are tied with 2 employees each, so both of their managers are returned.

Constraints

  • 1 <= employees.length <= 10^4
  • employees[i].length == 4
  • employees[i] = [emp_id, emp_name, dep_id, position]
  • emp_id and dep_id are string representations of positive integers
  • All emp_id values are unique
  • 1 <= emp_name.length, position.length <= 100
  • position is "Manager" for managers

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate