You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(employee_id, start_time) is the unique key for this table.
30
-
This table contains information about the shifts worked by employees, including the start and end times on a specific date.
29
+
(employee_id, start_time) 是此表的唯一主键。
30
+
这张表包含员工的排班工作,包括特定日期的开始和结束时间。
31
31
</pre>
32
32
33
-
<p>Write a solution to count the number of <strong>overlapping shifts</strong> for each employee. Two shifts are considered overlapping if one shift’s <code>end_time</code> is <strong>later than</strong> another shift’s <code>start_time</code>.</p>
These shifts overlap with each other, resulting in 1 overlapping shift.</li>
92
-
<li>Employee 3 has 3 shifts:
92
+
这些排班彼此重叠,因此有 1 个重叠排班。</li>
93
+
<li>员工 3 有 3 个排班:
93
94
<ul>
94
-
<li>10:00:00 to 12:00:00</li>
95
-
<li>13:00:00 to 15:00:00</li>
96
-
<li>16:00:00 to 18:00:00</li>
95
+
<li>10:00:00 到 12:00:00</li>
96
+
<li>13:00:00 到 15:00:00</li>
97
+
<li>16:00:00 到 18:00:00</li>
97
98
</ul>
98
-
None of these shifts overlap, so Employee 3 is not included in the output.</li>
99
-
<li>Employee 4 has 2 shifts:
99
+
这些排班没有重叠,所以员工 3 不包含在输出中。</li>
100
+
<li>员工 4 有 2 个排班:
100
101
<ul>
101
-
<li>08:00:00 to 10:00:00</li>
102
-
<li>09:00:00 to 11:00:00</li>
102
+
<li>08:00:00 到 10:00:00</li>
103
+
<li>09:00:00 到 11:00:00</li>
103
104
</ul>
104
-
These shifts overlap with each other, resulting in 1 overlapping shift.</li>
105
+
这些排班彼此重叠,因此有 1 个重叠排班。</li>
105
106
</ul>
106
107
107
-
<p>The output shows the employee_id and the count of overlapping shifts for each employee who has at least one overlapping shift, ordered by employee_id in ascending order.</p>
Copy file name to clipboardExpand all lines: solution/3200-3299/3262.Find Overlapping Shifts/README_EN.md
+17-22
Original file line number
Diff line number
Diff line change
@@ -113,17 +113,16 @@ This table contains information about the shifts worked by employees, including
113
113
114
114
<!-- solution:start -->
115
115
116
-
### Solution 1: Self-Join + Group Count
116
+
### Solution 1: Self-Join + Group Counting
117
117
118
-
We start by using a self-join to join the `EmployeeShifts` table with itself. The join condition ensures that only shifts of the same employee are compared, and checks if there is any overlap between the shifts.
118
+
We first use a self-join to connect the `EmployeeShifts` table to itself. The join condition ensures that we only compare shifts belonging to the same employee and check if there is any overlap between shifts.
119
119
120
-
1.`t1.start_time < t2.end_time`: Ensures that the start time of the first shift is earlier than the end time of the second shift.
120
+
1.`t1.start_time < t2.start_time`: Ensures that the start time of the first shift is earlier than the start time of the second shift.
121
121
2.`t1.end_time > t2.start_time`: Ensures that the end time of the first shift is later than the start time of the second shift.
122
-
3.`t1.start_time != t2.start_time`: Avoids comparing a shift with itself.
123
122
124
-
Next, we group the data by `employee_id` and count the number of overlapping shifts for each employee. We divide the count by 2 because each overlap is counted twice in the self-join.
123
+
Next, we group the data by `employee_id` and count the number of overlapping shifts for each employee.
125
124
126
-
Finally, we filter out employees with an overlapping shift count greater than 0 and sort the results in ascending order by `employee_id`.
125
+
Finally, we filter out employees with overlapping shift counts greater than $0$ and sort the results in ascending order by `employee_id`.
127
126
128
127
<!-- tabs:start -->
129
128
@@ -132,14 +131,13 @@ Finally, we filter out employees with an overlapping shift count greater than 0
0 commit comments