⌘K
Flycodx

Stock Market Moving Average

Stock Market Moving Average

MediumSliding Window25% accepted

Karan is a quant trader at a Mumbai hedge fund. He needs to compute the moving average of stock prices over a window of K days to identify trends. Given N daily prices, compute the moving average for every window of size K.

Approach

Given N stock prices and window size K, return the average of each consecutive window of K prices.

Input

16 2 452 113 430 64 454 229 155 144 444 183 237 237 454 220 89 346

Output

282.5 271.5 247 259 341.5 192 149.5 294 313.5 210 237 345.5 337 154.5 217.5
solution.py
Loading editor...
Test 1
Test 2
Test 3

Press Run to test your custom input, or Submit to judge against all test cases.

Sign in to continue

Create a free account to run code, submit solutions and track progress.

  • Free forever — no credit card
  • 10+ languages with live execution
  • Points, streaks & leaderboards
Auto Save OnLn 1, Col 1Spaces: 4UTF-8LFPython 3