Why 1tc is failed?

Hey @garganshul151
You are getting segmentation fault in 1 testcase for that update line 13 by long long *a=new long long[n];
i.e create the array dynamically.

why i have to do so ?

means why doing so remove error?

Hey u are getting segmentation error ,u can get it when you use more memory than available.
Right now you are declaring statically so memory is allocated on stack which of finite size.So this solution takes more memory than available in stack.
So hence we create dynamic array so that memory is allocated on heap instead of stack.
And I asked u to compute out of while loop to make it more efficient.