SOLVE

LATER

Calculate Moving Average

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.

Table : **Data**

Field | Type |
---|---|

Val | int |

Field | Type |
---|---|

MovingAverage | int |

**Sample Data Table:**

Val |
---|

1 |

2 |

10 |

15 |

12 |

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

Initializing Code Editor...

{"f572ea9": "/pagelets/problem-author-tester/sql/calculate-moving-average/", "aa2bb5b": "/pagelets/show-submission/sql/calculate-moving-average/", "c5a800a": "/pagelets/suggested-problems/sql/calculate-moving-average/", "79be1d3": "/pagelets/recommended-problems/sql/calculate-moving-average/", "9f1bb64": "/pagelets/problems-hint/sql/calculate-moving-average/"}

realtime.hackerearth.com

80

2b723389d7f780109c7257b549da81c1eede49b4

58a29e5cae2309f04b28

/realtime/pusher/auth/