Find out the time employees spend in the office for a day.
1Times asked
Jul 2026Last seen
Jul 2026First seen
💡 Model Answer
To calculate the time employees spend in the office, you need a log that records each employee’s check‑in and check‑out timestamps. The typical approach is:
- Load the log into a DataFrame or table.
- Ensure the timestamps are in a consistent format and cast them to a datetime type.
- Group the data by employee ID and date.
- For each group, sort the events chronologically and pair each check‑in with the next check‑out. If the data is clean, you can simply compute the difference between consecutive timestamps.
- Sum the differences for each employee per day to get the total time spent.
- Optionally, convert the total seconds to hours/minutes for readability.
Complexity is O(n) where n is the number of log entries. In SQL you could use window functions: LAG() to get the previous timestamp and then subtract. In Spark, use Window.partitionBy("emp_id", "date").orderBy("timestamp") and then compute the difference with lead() or lag().
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.
Get Assisting AI — Starts at ₹500