TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Rolling Standard Deviation

Time Series
Medium

Rolling standard deviation measures local variability over consecutive windows. Use population standard deviation, so a window of k values is divided by k rather than k - 1.

For each window, first compute its mean:

μi=1k∑j=0k−1xi+j\mu_i = \frac{1}{k}\sum_{j=0}^{k-1}x_{i+j}μi​=k1​j=0∑k−1​xi+j​

Then compute its population standard deviation:

σi=1k∑j=0k−1(xi+j−μi)2\sigma_i = \sqrt{\frac{1}{k}\sum_{j=0}^{k-1}(x_{i+j}-\mu_i)^2}σi​=k1​j=0∑k−1​(xi+j​−μi​)2​

Here, i is the window's starting index and k is window_size. Return one standard deviation for every complete window.

Loading visualization...

Examples

Input: values = [1, 2, 3, 4, 5], window_size = 3

Output: [0.816497, 0.816497, 0.816497]

Explanation: Every three-value window has population variance 2/3, so each standard deviation is the square root of 2/3.

Input: values = [5, 5, 5, 5], window_size = 2

Output: [0.0, 0.0, 0.0]

Hint 1

Compute the mean separately for each slice of length window_size.

Hint 2

Take the square root after averaging the squared deviations.

Requirements

  • Compute the population standard deviation for each complete window.
  • Divide the squared-deviation sum by window_size.
  • Return len(values) - window_size + 1 values.
  • Return a list of floats.

Constraints

  • 1 <= window_size <= len(values).
  • values contains numeric values.
  • Time limit: 300 ms.
Try Similar Problems
Simple Moving AverageExponential Moving AverageMoving MedianWeighted Moving AverageSample Var Std

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: number

You must run your code first.
PrevNext

Rolling Standard Deviation

Time Series
Medium

Rolling standard deviation measures local variability over consecutive windows. Use population standard deviation, so a window of k values is divided by k rather than k - 1.

For each window, first compute its mean:

μi=1k∑j=0k−1xi+j\mu_i = \frac{1}{k}\sum_{j=0}^{k-1}x_{i+j}μi​=k1​j=0∑k−1​xi+j​

Then compute its population standard deviation:

σi=1k∑j=0k−1(xi+j−μi)2\sigma_i = \sqrt{\frac{1}{k}\sum_{j=0}^{k-1}(x_{i+j}-\mu_i)^2}σi​=k1​j=0∑k−1​(xi+j​−μi​)2​

Here, i is the window's starting index and k is window_size. Return one standard deviation for every complete window.

Loading visualization...

Examples

Input: values = [1, 2, 3, 4, 5], window_size = 3

Output: [0.816497, 0.816497, 0.816497]

Explanation: Every three-value window has population variance 2/3, so each standard deviation is the square root of 2/3.

Input: values = [5, 5, 5, 5], window_size = 2

Output: [0.0, 0.0, 0.0]

Hint 1

Compute the mean separately for each slice of length window_size.

Hint 2

Take the square root after averaging the squared deviations.

Requirements

  • Compute the population standard deviation for each complete window.
  • Divide the squared-deviation sum by window_size.
  • Return len(values) - window_size + 1 values.
  • Return a list of floats.

Constraints

  • 1 <= window_size <= len(values).
  • values contains numeric values.
  • Time limit: 300 ms.
Try Similar Problems
Simple Moving AverageExponential Moving AverageMoving MedianWeighted Moving AverageSample Var Std

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: number

You must run your code first.