Time-Weighted Average Battery Level From Sparse Meta Quest Telemetry

Last updated: November 29, 2026

Quick Overview

Meta Quest headsets report battery level only when it changes or every few minutes. Write a Python function that treats the readings as a step function and returns the time-weighted average battery level over a given time window.

Meta
Data Manipulation (SQL/Python)
Software Engineer
Meta
November 29, 2026
Software Engineer
Phone Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Meta Quest headsets report battery level only when it changes or every few minutes. Write a Python function that treats the readings as a step function and returns the time-weighted average battery level over a given time window.

A Python phone screen for Meta Reality Labs engineers who work with device telemetry, where samples are irregular and a simple mean is biased toward periods with frequent reporting. The interviewer checks interval clipping and the meaning of the value before the first sample.

What the Interviewer Expects
  • Treat each sample as valid until the next one
  • Clip each interval to the query window
  • Weight by duration, not by count
  • Exclude time before the first sample instead of guessing
  • Return None when no value is known in the window
Key Topics to Cover
step functions
time-weighted average
interval clipping
telemetry
Python
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
  • Why is the simple mean of samples wrong here?
  • How would you handle a device that stopped reporting for six hours?
  • How would you compute this for every hour of the day per device?
  • When would linear interpolation be better than a step function?
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

Input: a list of (ts, value) sorted by ts, and a half-open window [start, end). Each reading holds until the next reading; the last one holds until end. Before the first reading the level is unk...

Approach

Iterate over readings, pairing each with the next timestamp (or end). Clip the interval to the window with max and min; if it has positive length, add value * length to the total and length ...


Submit Your Answer
Markdown supported