#3611
Find Overbooked Employees
MediumDatabaseHash MapArray
Approaches
Brute ForceOptimal
Complexity Comparison
| Brute Force | Optimal Solution★ | |
|---|---|---|
| Time | O(n²) | O(n) |
| Space | O(1) | O(n) |
💡
Intuition
Time O(n)Space O(n)
Use a single pass to aggregate meeting hours by week for each employee, then filter those exceeding 20 hours. This reduces redundant calculations.
⚙️
Algorithm
3 steps- 1Step 1: Group meetings by employee and week, summing durations.
- 2Step 2: Filter employees whose total meeting hours exceed 20 hours.
- 3Step 3: Return the list of overbooked employees.
solution.py1 lines
1SELECT employee_id, employee_name FROM employees e JOIN (SELECT employee_id, YEAR(meeting_date) AS year, WEEK(meeting_date) AS week, SUM(duration_hours) AS total_hours FROM meetings GROUP BY employee_id, year, week) m ON e.employee_id = m.employee_id WHERE total_hours > 20ℹ
Complexity note: Single pass aggregation leads to linear time complexity, with space used for storing intermediate results.
- 1Meeting hours can be aggregated by week.
- 2Filtering after aggregation is efficient.
Solutions and explanations are original Tejav content. Problem titles © LeetCode — use the LeetCode button above for the full problem statement.