Split Overnight Fulfillment Center Shifts Into Hours Worked per Day

Last updated: November 29, 2026

Quick Overview

Fulfillment center associates often work night shifts that cross midnight. Given shifts (associate_id, start_ts, end_ts) in UTC, use pandas to split each shift at local midnight for the site's timezone and return total hours worked per associate per local calendar day, correct across daylight saving changes.

Amazon
Data Manipulation (SQL/Python)
Data Engineer
Amazon
November 29, 2026
Data Engineer
Take-home Project
Data Manipulation (SQL/Python)
Hard

0

0

0 solved


Fulfillment center associates often work night shifts that cross midnight. Given shifts (associate_id, start_ts, end_ts) in UTC, use pandas to split each shift at local midnight for the site's timezone and return total hours worked per associate per local calendar day, correct across daylight saving changes.

Amazon operations tracks labor hours per day for planning, overtime rules and productivity rates, and night shifts at fulfillment centers break naive date grouping. This take-home style task tests interval splitting, timezone-aware arithmetic and the DST edge case where a local day is 25 hours long.

What the Interviewer Expects
  • Convert to the site's local timezone before determining day boundaries
  • Split intervals at each local midnight, including shifts spanning more than one midnight
  • Compute durations as differences of tz-aware timestamps so DST is respected
  • Drop or report invalid shifts where end is not after start
  • Aggregate pieces back to associate and day
Key Topics to Cover
interval splitting
timezones
daylight saving time
time series aggregation
pandas
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you vectorize this for tens of millions of shifts?
  • How would you attribute a night shift to its start date instead, and when would payroll prefer that?
  • How would you subtract unpaid breaks recorded in a separate table?
  • How would you handle sites in different timezones in one dataset?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data
  • shifts(associate_id, start_ts, end_ts) in UTC; all rows belong to one site, here in America/Los_Angeles.
  • Hours count toward the local calendar day in which they were worked, so a 22:00 to 06:00 ...
Approach

For each shift, walk from start to end: find the next local midnight, cut the piece there, emit (associate, local date, hours), and continue. Next midnight is computed on naive wall-clock time (drop...


Submit Your Answer
Markdown supported