PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/DRW

Compute rolling standard deviation in O(n)

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of streaming statistics, numerical stability, and incremental algorithm design for rolling variance and standard deviation while also testing handling of edge cases and special numeric values.

  • Medium
  • DRW
  • Coding & Algorithms
  • Data Scientist

Compute rolling standard deviation in O(n)

Company: DRW

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Given an array of numbers and a window size k, compute the rolling standard deviation for every contiguous window. Design an O(n) algorithm that updates statistics incrementally rather than recomputing each window from scratch. Use the variance identity by maintaining running sum and sum of squares (or adapt a one-pass method like Welford’s algorithm for a sliding window), discuss numerical stability, analyze time and space complexity, and handle edge cases (k ≤ 0, k > n, k = 1, NaNs). Implement and provide tests.

Quick Answer: This question evaluates understanding of streaming statistics, numerical stability, and incremental algorithm design for rolling variance and standard deviation while also testing handling of edge cases and special numeric values.

Related Interview Questions

  • Solve three algorithmic OA problems - DRW (medium)
  • Solve odd-string, digit swap, patient slot assignment - DRW (Medium)
  • Solve movie ratings, array, release scheduler - DRW (Medium)
  • Implement portfolio optimization simulation - DRW (Medium)
  • Solve three algorithmic OA tasks - DRW (Medium)
DRW logo
DRW
Aug 9, 2025, 12:00 AM
Data Scientist
Technical Screen
Coding & Algorithms
3
0

Given an array of numbers and a window size k, compute the rolling standard deviation for every contiguous window. Design an O(n) algorithm that updates statistics incrementally rather than recomputing each window from scratch. Use the variance identity by maintaining running sum and sum of squares (or adapt a one-pass method like Welford’s algorithm for a sliding window), discuss numerical stability, analyze time and space complexity, and handle edge cases (k ≤ 0, k > n, k = 1, NaNs). Implement and provide tests.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More DRW•More Data Scientist•DRW Data Scientist•DRW Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

Master your tech interviews with 7,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.