**Can you give us some hints for the Bonus Challenge ?**An example may help to clarify the issues. Suppose the input is

[1 0 0 1 0 2]

The parameters`a`

,`b`

and`c`

must be chosen to minimize this function:`E = (0 - (b + c))`

^{2}+ (1 - c)^{2}+ (0 - (a + c))^{2}+ (2 - (b + c))^{2}The minimum of this function (which is quadratic and positive definite) will occur at the place where the derivatives of

`E`

with respect to`a`

,`b`

and`c`

are zero. These derivatives are:dE -- = 2(a + c) da dE -- = 2(b + c) - 2(2 - (b + c)) = 4(b + c - 1) db dE -- = 2(b + c) - 2(1 - c) + 2(a + c) - 2(2 - (b + c)) = 2(a + 2b + 4c - 3) dc

Solving these equations simultaneously gives`a=-1`

,`b=0`

,`c=1`

;

so new items in the sequence will be predicted according to the equationu

_{k}= au_{k-1}+ bu_{k-2}+ c = -u_{k-1}+ 1The output is therefore

[-1 2 -1 2 -1]

In general, we haveE = Σ

_{1<k<n}[ u_{k}- (au_{k-1}+ bu_{k-2}+ c)]^{2}So the derivatives are:

d

_{a}E = Σ_{1<k<n}-2u_{k-1}[ u_{k}- (au_{k-1}+ bu_{k-2}+ c)] = 2[-Σu_{k-1}u_{k}+ Σu_{k-1}^{2}a + Σu_{k-1}u_{k-2}b + Σu_{k-1}c]

d_{b}E = Σ_{1<k<n}-2u_{k-2}[ u_{k}- (au_{k-1}+ bu_{k-2}+ c)] = 2[-Σu_{k-2}u_{k}+ Σu_{k-2}u_{k-1}a + Σu_{k-2}^{2}b + Σu_{k-2}c]

d_{c}E = Σ_{1<k<n}-2[ u_{k}- (au_{k-1}+ bu_{k-2}+ c)] = 2[-Σu_{k}+ Σu_{k-1}a + Σu_{k-2}b + (n-2)c]

This gives three simultaneous equations, whose coefficients can be updated for each new item in the sequence. Solve them simultaneously and you will obtain

`a,b,c`

.**Do we need to worry about roundoff errors, etc, for the Bonus Challenge ?**For the Bonus Challenge, the automarking script will try to avoid using any data that could cause a division by zero, so it shouldn't be a problem.

**Are we required to use only "constant space" ?**Although this is possible, it is not required; i.e. you are welcome to use an array or

`ArrayList`

, etc, if you like; and you may assume there will be no more than 128 items in the input.