Compute centered averages and merge intervals
Company: WeRide
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Technical Screen
You are given two Python/pandas tasks.
1. Centered sliding window average:
Given a pandas DataFrame `df` sorted in row order with columns `row_id` (int) and `value` (float), and an integer `k >= 0`, create a new column `window_avg`. For each row `i`, compute the average of `value` from rows `i-k` through `i+k`, inclusive. If a row does not have at least `k` previous rows and `k` later rows, set `window_avg = -1` for that row.
2. Merge intervals in pandas:
Given a pandas DataFrame `intervals` with columns `start` (int) and `end` (int), where each row represents a time interval for an autonomous driving event and `start <= end`, merge all overlapping intervals and return a DataFrame of non-overlapping intervals sorted by `start`.
Quick Answer: This question evaluates proficiency in Python pandas data manipulation and algorithmic reasoning focused on centered sliding-window aggregation and merging overlapping intervals.