I'm writing code to compute a single value answer to a given numbers in integer array such that step sum is calculated till only 1 number is left.For example:Input:3,5,2,6,7Output is computed as:(3+5)+(5+2)+(2+6)+(6+7)It remains like this till I only have a single number left.3   5   2   6   7  8   7   8  13   15  15  21     30  36       66int inputarray={3,5,2,6,7};int inputlength=inputarray.length;   while(inputlength!=0)   {     for(int i=0;i<inputlength-1;i++)   {      inputarray[i]=inputarray[i+1]+inputarray[i];         }   inputlength--;   }    System.out.println(inputarray[0]);It computes the result in quadratic growth.  Is there any way to compute my result more efficiently? What else can I do to improve it?
Single value computation
java;algorithm
So spoke TartagliaAn optimized solution should make use of the Tartaglia's Triangle that is so constructed:     1    1 1   1 2 1  1 3 3 1 1 4 6 4 1You could generate it or memorize it, your choice.The solution is simply multiplying input with Tartaglia's Triangle coefficients of the nth row where n is the total number of input, as multipliers and then adding all together.Show don't tellfor a in range(10):    for b in range(10):        for c in range(10):            assert tree_addition([a,b,c]) == a + b*2 + cfor a in range(10):    for b in range(10):        for c in range(10):            for d in range(10):                 assert tree_addition([a,b,c,d]) == a + b*3 + c*3 + dfor a in range(10):    for b in range(10):        for c in range(10):            for d in range(10):                for e in range(10):                    assert tree_addition([a,b,c,d,e]) == a + b*4 + c*6 + d*4 + eShould explain my point more clearly, note the the code above always works.