LeetCode 1741: Find Total Time Spent by Each Employee
Problem Description
Explanation:
To solve this problem, we need to calculate the total time spent by each employee on each day at the office. We can achieve this by grouping the entries by employee and day, and then summing up the time differences between in_time and out_time for each group.
- We will group the entries by emp_id and event_day.
- For each group, we will calculate the total time spent by summing the differences between out_time and in_time.
- Finally, we will output the results in the desired format.
Time Complexity: O(n), where n is the number of entries in the Employees table. Space Complexity: O(n) for storing the results.
:
Solutions
# Java Solution
# Write your Java solution here
SELECT event_day AS day, emp_id, SUM(out_time - in_time) AS total_time
FROM Employees
ORDER BY event_day, emp_id;
Loading editor...