Off-by-one on range boundaries
Wrong move: Loop endpoints miss first/last candidate.
Usually fails on: Fails on minimal arrays and exact-boundary answers.
Fix: Re-derive loops from inclusive/exclusive ranges before coding.
Move from brute-force thinking to an efficient approach using core interview patterns strategy.
Table: employees
+---------------+---------+ | Column Name | Type | +---------------+---------+ | employee_id | int | | employee_name | varchar | | department | varchar | +---------------+---------+ employee_id is the unique identifier for this table. Each row contains information about an employee and their department.
Table: meetings
+---------------+---------+ | Column Name | Type | +---------------+---------+ | meeting_id | int | | employee_id | int | | meeting_date | date | | meeting_type | varchar | | duration_hours| decimal | +---------------+---------+ meeting_id is the unique identifier for this table. Each row represents a meeting attended by an employee. meeting_type can be 'Team', 'Client', or 'Training'.
Write a solution to find employees who are meeting-heavy - employees who spend more than 50% of their working time in meetings during any given week.
40 hours> 20 hours (50% of 40 hours)2 weeksReturn the result table ordered by the number of meeting-heavy weeks in descending order, then by employee name in ascending order.
The result format is in the following example.
Example:
Input:
employees table:
+-------------+----------------+-------------+ | employee_id | employee_name | department | +-------------+----------------+-------------+ | 1 | Alice Johnson | Engineering | | 2 | Bob Smith | Marketing | | 3 | Carol Davis | Sales | | 4 | David Wilson | Engineering | | 5 | Emma Brown | HR | +-------------+----------------+-------------+
meetings table:
+------------+-------------+--------------+--------------+----------------+ | meeting_id | employee_id | meeting_date | meeting_type | duration_hours | +------------+-------------+--------------+--------------+----------------+ | 1 | 1 | 2023-06-05 | Team | 8.0 | | 2 | 1 | 2023-06-06 | Client | 6.0 | | 3 | 1 | 2023-06-07 | Training | 7.0 | | 4 | 1 | 2023-06-12 | Team | 12.0 | | 5 | 1 | 2023-06-13 | Client | 9.0 | | 6 | 2 | 2023-06-05 | Team | 15.0 | | 7 | 2 | 2023-06-06 | Client | 8.0 | | 8 | 2 | 2023-06-12 | Training | 10.0 | | 9 | 3 | 2023-06-05 | Team | 4.0 | | 10 | 3 | 2023-06-06 | Client | 3.0 | | 11 | 4 | 2023-06-05 | Team | 25.0 | | 12 | 4 | 2023-06-19 | Client | 22.0 | | 13 | 5 | 2023-06-05 | Training | 2.0 | +------------+-------------+--------------+--------------+----------------+
Output:
+-------------+----------------+-------------+---------------------+ | employee_id | employee_name | department | meeting_heavy_weeks | +-------------+----------------+-------------+---------------------+ | 1 | Alice Johnson | Engineering | 2 | | 4 | David Wilson | Engineering | 2 | +-------------+----------------+-------------+---------------------+
Explanation:
The result table is ordered by meeting_heavy_weeks in descending order, then by employee name in ascending order.
Problem summary: Table: employees +---------------+---------+ | Column Name | Type | +---------------+---------+ | employee_id | int | | employee_name | varchar | | department | varchar | +---------------+---------+ employee_id is the unique identifier for this table. Each row contains information about an employee and their department. Table: meetings +---------------+---------+ | Column Name | Type | +---------------+---------+ | meeting_id | int | | employee_id | int | | meeting_date | date | | meeting_type | varchar | | duration_hours| decimal | +---------------+---------+ meeting_id is the unique identifier for this table. Each row represents a meeting attended by an employee. meeting_type can be 'Team', 'Client', or 'Training'. Write a solution to find employees who are meeting-heavy - employees who spend more than 50% of their working time in meetings during any given week. Assume a standard work
Start with the most direct exhaustive search. That gives a correctness anchor before optimizing.
Pattern signal: General problem-solving
{"headers":{"employees":["employee_id","employee_name","department"],"meetings":["meeting_id","employee_id","meeting_date","meeting_type","duration_hours"]},"rows":{"employees":[[1,"Alice Johnson","Engineering"],[2,"Bob Smith","Marketing"],[3,"Carol Davis","Sales"],[4,"David Wilson","Engineering"],[5,"Emma Brown","HR"]],"meetings":[[1,1,"2023-06-05","Team",8.0],[2,1,"2023-06-06","Client",6.0],[3,1,"2023-06-07","Training",7.0],[4,1,"2023-06-12","Team",12.0],[5,1,"2023-06-13","Client",9.0],[6,2,"2023-06-05","Team",15.0],[7,2,"2023-06-06","Client",8.0],[8,2,"2023-06-12","Training",10.0],[9,3,"2023-06-05","Team",4.0],[10,3,"2023-06-06","Client",3.0],[11,4,"2023-06-05","Team",25.0],[12,4,"2023-06-19","Client",22.0],[13,5,"2023-06-05","Training",2.0]]}}Source-backed implementations are provided below for direct study and interview prep.
// Accepted solution for LeetCode #3611: Find Overbooked Employees
// Auto-generated Java example from py.
class Solution {
public void exampleSolution() {
}
}
// Reference (py):
// # Accepted solution for LeetCode #3611: Find Overbooked Employees
// import pandas as pd
//
//
// def find_overbooked_employees(
// employees: pd.DataFrame, meetings: pd.DataFrame
// ) -> pd.DataFrame:
// meetings["meeting_date"] = pd.to_datetime(meetings["meeting_date"])
// meetings["year"] = meetings["meeting_date"].dt.isocalendar().year
// meetings["week"] = meetings["meeting_date"].dt.isocalendar().week
//
// week_meeting_hours = (
// meetings.groupby(["employee_id", "year", "week"], as_index=False)[
// "duration_hours"
// ]
// .sum()
// .rename(columns={"duration_hours": "hours"})
// )
//
// intensive_weeks = week_meeting_hours[week_meeting_hours["hours"] >= 20]
//
// intensive_count = (
// intensive_weeks.groupby("employee_id")
// .size()
// .reset_index(name="meeting_heavy_weeks")
// )
//
// result = intensive_count.merge(employees, on="employee_id")
//
// result = result[result["meeting_heavy_weeks"] >= 2]
//
// result = result.sort_values(
// ["meeting_heavy_weeks", "employee_name"], ascending=[False, True]
// )
//
// return result[
// ["employee_id", "employee_name", "department", "meeting_heavy_weeks"]
// ].reset_index(drop=True)
// Accepted solution for LeetCode #3611: Find Overbooked Employees
// Auto-generated Go example from py.
func exampleSolution() {
}
// Reference (py):
// # Accepted solution for LeetCode #3611: Find Overbooked Employees
// import pandas as pd
//
//
// def find_overbooked_employees(
// employees: pd.DataFrame, meetings: pd.DataFrame
// ) -> pd.DataFrame:
// meetings["meeting_date"] = pd.to_datetime(meetings["meeting_date"])
// meetings["year"] = meetings["meeting_date"].dt.isocalendar().year
// meetings["week"] = meetings["meeting_date"].dt.isocalendar().week
//
// week_meeting_hours = (
// meetings.groupby(["employee_id", "year", "week"], as_index=False)[
// "duration_hours"
// ]
// .sum()
// .rename(columns={"duration_hours": "hours"})
// )
//
// intensive_weeks = week_meeting_hours[week_meeting_hours["hours"] >= 20]
//
// intensive_count = (
// intensive_weeks.groupby("employee_id")
// .size()
// .reset_index(name="meeting_heavy_weeks")
// )
//
// result = intensive_count.merge(employees, on="employee_id")
//
// result = result[result["meeting_heavy_weeks"] >= 2]
//
// result = result.sort_values(
// ["meeting_heavy_weeks", "employee_name"], ascending=[False, True]
// )
//
// return result[
// ["employee_id", "employee_name", "department", "meeting_heavy_weeks"]
// ].reset_index(drop=True)
# Accepted solution for LeetCode #3611: Find Overbooked Employees
import pandas as pd
def find_overbooked_employees(
employees: pd.DataFrame, meetings: pd.DataFrame
) -> pd.DataFrame:
meetings["meeting_date"] = pd.to_datetime(meetings["meeting_date"])
meetings["year"] = meetings["meeting_date"].dt.isocalendar().year
meetings["week"] = meetings["meeting_date"].dt.isocalendar().week
week_meeting_hours = (
meetings.groupby(["employee_id", "year", "week"], as_index=False)[
"duration_hours"
]
.sum()
.rename(columns={"duration_hours": "hours"})
)
intensive_weeks = week_meeting_hours[week_meeting_hours["hours"] >= 20]
intensive_count = (
intensive_weeks.groupby("employee_id")
.size()
.reset_index(name="meeting_heavy_weeks")
)
result = intensive_count.merge(employees, on="employee_id")
result = result[result["meeting_heavy_weeks"] >= 2]
result = result.sort_values(
["meeting_heavy_weeks", "employee_name"], ascending=[False, True]
)
return result[
["employee_id", "employee_name", "department", "meeting_heavy_weeks"]
].reset_index(drop=True)
// Accepted solution for LeetCode #3611: Find Overbooked Employees
// Rust example auto-generated from py reference.
// Replace the signature and local types with the exact LeetCode harness for this problem.
impl Solution {
pub fn rust_example() {
// Port the logic from the reference block below.
}
}
// Reference (py):
// # Accepted solution for LeetCode #3611: Find Overbooked Employees
// import pandas as pd
//
//
// def find_overbooked_employees(
// employees: pd.DataFrame, meetings: pd.DataFrame
// ) -> pd.DataFrame:
// meetings["meeting_date"] = pd.to_datetime(meetings["meeting_date"])
// meetings["year"] = meetings["meeting_date"].dt.isocalendar().year
// meetings["week"] = meetings["meeting_date"].dt.isocalendar().week
//
// week_meeting_hours = (
// meetings.groupby(["employee_id", "year", "week"], as_index=False)[
// "duration_hours"
// ]
// .sum()
// .rename(columns={"duration_hours": "hours"})
// )
//
// intensive_weeks = week_meeting_hours[week_meeting_hours["hours"] >= 20]
//
// intensive_count = (
// intensive_weeks.groupby("employee_id")
// .size()
// .reset_index(name="meeting_heavy_weeks")
// )
//
// result = intensive_count.merge(employees, on="employee_id")
//
// result = result[result["meeting_heavy_weeks"] >= 2]
//
// result = result.sort_values(
// ["meeting_heavy_weeks", "employee_name"], ascending=[False, True]
// )
//
// return result[
// ["employee_id", "employee_name", "department", "meeting_heavy_weeks"]
// ].reset_index(drop=True)
// Accepted solution for LeetCode #3611: Find Overbooked Employees
// Auto-generated TypeScript example from py.
function exampleSolution(): void {
}
// Reference (py):
// # Accepted solution for LeetCode #3611: Find Overbooked Employees
// import pandas as pd
//
//
// def find_overbooked_employees(
// employees: pd.DataFrame, meetings: pd.DataFrame
// ) -> pd.DataFrame:
// meetings["meeting_date"] = pd.to_datetime(meetings["meeting_date"])
// meetings["year"] = meetings["meeting_date"].dt.isocalendar().year
// meetings["week"] = meetings["meeting_date"].dt.isocalendar().week
//
// week_meeting_hours = (
// meetings.groupby(["employee_id", "year", "week"], as_index=False)[
// "duration_hours"
// ]
// .sum()
// .rename(columns={"duration_hours": "hours"})
// )
//
// intensive_weeks = week_meeting_hours[week_meeting_hours["hours"] >= 20]
//
// intensive_count = (
// intensive_weeks.groupby("employee_id")
// .size()
// .reset_index(name="meeting_heavy_weeks")
// )
//
// result = intensive_count.merge(employees, on="employee_id")
//
// result = result[result["meeting_heavy_weeks"] >= 2]
//
// result = result.sort_values(
// ["meeting_heavy_weeks", "employee_name"], ascending=[False, True]
// )
//
// return result[
// ["employee_id", "employee_name", "department", "meeting_heavy_weeks"]
// ].reset_index(drop=True)
Use this to step through a reusable interview workflow for this problem.
Two nested loops check every pair or subarray. The outer loop fixes a starting point, the inner loop extends or searches. For n elements this gives up to n²/2 operations. No extra space, but the quadratic time is prohibitive for large inputs.
Most array problems have an O(n²) brute force (nested loops) and an O(n) optimal (single pass with clever state tracking). The key is identifying what information to maintain as you scan: a running max, a prefix sum, a hash map of seen values, or two pointers.
Review these before coding to avoid predictable interview regressions.
Wrong move: Loop endpoints miss first/last candidate.
Usually fails on: Fails on minimal arrays and exact-boundary answers.
Fix: Re-derive loops from inclusive/exclusive ranges before coding.