All Tracks Problem

Calculate Moving Average
Tag(s):

Easy-Medium, Fácil-Medio, Fácil-médio, 简单偏中, 簡単-普通

Problem
Editorial
Analytics

Fredo has recently learned about Moving Average wherein we forecast the next data value based on N previous data values. He got a table of data values for which he needs to find the moving average with N=3. The table consists of one field as described below:
1. Val: Data value.

You have to find the moving average(ceil value) for all the data values in the table for which the moving average exists. The moving average of initial three values will not exist as for them we don't have 3 previous data values. So, you need to find the moving average from \(4^{th}\) data value to last data value.

Input Format:

Table : Data

Field Type
Val int

Output Format:

Field Type
MovingAverage int

Sample Input:

Sample Data Table:

Val
1
2
10
15
12

Sample Output:

MovingAverage
5
9

Explanation:

Moving average for data value \(15= (1+2+10)/3 = 4.3333\). Ceil value of 4.3333 is 5.
Moving average for data value \(12= (2+10+15)/3 = 9.0000\). Ceil value of 9.0000 is 9.

Time Limit: 5 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: MySQL, PostgreSQL, MSSQL, Oracle_Db

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

Notifications
View All Notifications

?