PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Data Manipulation (SQL/Python)/WeRide

Compute window averages and merge intervals

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in pandas-based data manipulation—specifically windowed aggregations with strict boundary conditions and group-wise temporal interval merging—demonstrating skills in rolling/window operations, grouping, sorting, and handling time-based overlaps.

  • medium
  • WeRide
  • Data Manipulation (SQL/Python)
  • Data Scientist

Compute window averages and merge intervals

Company: WeRide

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Technical Screen

You are given two independent pandas tasks. 1. **Sliding-window average** - Input DataFrame: `df` - Schema: - `row_id` INT — unique row order key, already sorted ascending - `value` FLOAT - Given an integer `k >= 0`, compute for each row the average of the values from the previous `k` rows, the current row, and the next `k` rows. - If a row does not have at least `k` previous rows and `k` next rows, set the output to `-1` for that row. - Return a DataFrame with columns: `row_id`, `value`, `window_avg`. 2. **Merge overlapping autonomous-driving intervals** - Input DataFrame: `segments` - Schema: - `vehicle_id` STRING - `event_type` STRING - `start_ts` TIMESTAMP - `end_ts` TIMESTAMP - Assume all timestamps are in the same timezone and `start_ts <= end_ts` for every row. - For each `(vehicle_id, event_type)` independently, merge intervals that overlap or touch, where a new interval should be merged into the current one if `next.start_ts <= current.end_ts`. - Return the merged result with columns: `vehicle_id`, `event_type`, `merged_start_ts`, `merged_end_ts`, sorted by `vehicle_id`, `event_type`, `merged_start_ts`. Write pandas code for both tasks.

Quick Answer: This question evaluates proficiency in pandas-based data manipulation—specifically windowed aggregations with strict boundary conditions and group-wise temporal interval merging—demonstrating skills in rolling/window operations, grouping, sorting, and handling time-based overlaps.

Related Interview Questions

  • Compute centered averages and merge intervals - WeRide (medium)
  • Compute Rolling Averages and Merge Intervals - WeRide (medium)
WeRide logo
WeRide
Jan 23, 2025, 12:00 AM
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
2
0

You are given two independent pandas tasks.

  1. Sliding-window average
    • Input DataFrame: df
    • Schema:
      • row_id INT — unique row order key, already sorted ascending
      • value FLOAT
    • Given an integer k >= 0 , compute for each row the average of the values from the previous k rows, the current row, and the next k rows.
    • If a row does not have at least k previous rows and k next rows, set the output to -1 for that row.
    • Return a DataFrame with columns: row_id , value , window_avg .
  2. Merge overlapping autonomous-driving intervals
    • Input DataFrame: segments
    • Schema:
      • vehicle_id STRING
      • event_type STRING
      • start_ts TIMESTAMP
      • end_ts TIMESTAMP
    • Assume all timestamps are in the same timezone and start_ts <= end_ts for every row.
    • For each (vehicle_id, event_type) independently, merge intervals that overlap or touch, where a new interval should be merged into the current one if next.start_ts <= current.end_ts .
    • Return the merged result with columns: vehicle_id , event_type , merged_start_ts , merged_end_ts , sorted by vehicle_id , event_type , merged_start_ts .

Write pandas code for both tasks.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Data Manipulation (SQL/Python)•More WeRide•More Data Scientist•WeRide Data Scientist•WeRide Data Manipulation (SQL/Python)•Data Scientist Data Manipulation (SQL/Python)
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.