Practice/Apple/Leetcode 184. Department Highest Salary
CodingOptional
You are given two tables representing employee and department data. Your task is to identify the top-earning employee(s) in each department. When multiple employees in the same department share the maximum salary, all of them should be included in the results.
The Employee table contains employee records with their salaries and department associations. The Department table contains department information with unique identifiers and names.
Example 1:
` Input: employees = [[1, "Alice", 90000, 1], [2, "Bob", 80000, 1], [3, "Charlie", 95000, 2]] departments = [[1, "Engineering"], [2, "Sales"]]
Output: "Engineering,Alice,90000;Sales,Charlie,95000"
Explanation: Alice earns the most in Engineering (90000) and Charlie earns the most in Sales (95000). `
Example 2:
` Input: employees = [[1, "Emma", 100000, 1], [2, "Frank", 100000, 1], [3, "Grace", 90000, 1]] departments = [[1, "Marketing"]]
Output: "Marketing,Emma,100000;Marketing,Frank,100000"
Explanation: Emma and Frank both earn 100000 in Marketing, which is the maximum salary. Both are included in the result. `
Example 3:
` Input: employees = [[1, "Jack", 95000, 1]] departments = [[1, "Operations"], [2, "Legal"]]
Output: "Operations,Jack,95000"
Explanation: The Legal department has no employees, so only Operations is included in the output. `