Algorithm to find out the number of times a number occurs consecutively in an array in a range specified
Define a sub problem solution as the range of longest sub series.
If there are more than one we solution is 2 at most. The once at the tips of the range.
and there are exactly (n^2-n)/2 sub problems here.
You can solve each sub problem in o(n).

If you were to remember the results of problems you solved. 
You can remember all in o(n*(n^2-n)/2) and it's fine.

But, If you consider Dynamic programming. 
There is a bottom up series to solve each sub problem in o(1) time.

when trying to solve(i,j) two cases are to consider:

the range is at the tip. so consider increasing the result.
the range is at the tip. just return the longest. again up to 2 ranges.