Before I get into the solution, let me tell you how this sequence helped me in solving the Best Index problem on Hackerearth.
What is the Best Index of an array?
An index of the array is called best if the special sum of this index is maximum across the special sum of all the other indices.
The problem expects to print the best index of the input array. The best index for any index i is calculated using the below formula -
( A[i] ) + ( A[i+1] + A[i+2] ) +( A[i+3] + A[i+4] + A[i+5] )……
So for array with size 10, best index for ‘index 2’ will be
( A ) + ( A + A ) +( A + A + A )
Indices 8 and 9 will be ignored since we need 4 more elements, after grouping 3 elements at indices 5, 6 and 7.
I solved the above problem in Golang. Please refer the solution here. Line 28–32 in the above solution handles the sequence generation of 1, 3, 6, 10…
So lets say i is initialised to 1 and n to 10. We need to print the sequence till n. Check this program which will print the required result.