this is code is written according to logic of hint give
but as after the iterations of while loop j comes out with one value greater and the answer is coming 19 for array 1,2,3 as it should be 10.
so how should i think to resolve this issue as i applied the given formula as it is