Compare Each Day's Audible Listening Hours to the Same Weekday Last Week

Last updated: November 29, 2026

Quick Overview

From daily Audible listening totals, compute each day's hours, the hours on the same weekday one week earlier, and the week-over-week percentage change.

Amazon
Data Manipulation (SQL/Python)
Data Scientist
Amazon
November 29, 2026
Data Scientist
Online Assessment
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


From daily Audible listening totals, compute each day's hours, the hours on the same weekday one week earlier, and the week-over-week percentage change.

An easy window function item in the style of Amazon online assessments, framed on Audible engagement where weekday patterns are strong. The interviewer checks LAG with an offset, and whether you notice that an offset of seven rows equals seven days only if no days are missing.

What the Interviewer Expects
  • Aggregate to one row per day
  • Use LAG with an offset of 7 to reach the same weekday
  • Verify the lagged row is exactly seven days earlier
  • Compute percentage change with safe division
  • Explain why weekday comparison beats day-over-day here
Key Topics to Cover
LAG offset
week over week
seasonality
date checks
NULLIF
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 compare to the average of the same weekday over the last four weeks?
  • How would you do this per marketplace?
  • How would you flag days where the change is unusually large?
  • What changes around holidays that move between weekdays?
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

Table listening_events(customer_id, title_id, start_ts, seconds_listened). Daily totals are in hours, UTC days. Questions: is the data complete for every day (I will check rather than assume), and s...

Approach

Listening is strongly weekly, with commute days looking different from weekends, so comparing Monday to Sunday mostly measures the weekly cycle. Comparing to the same weekday a week earlier removes mo...


Submit Your Answer
Markdown supported