Problem in solving this question

https://hack.codingblocks.com/app/practice/3/1001/problem

@avnoorsingh488
hello avnoor,
what problem u are facing?

@avnoorsingh488
if n will be even then answer will always be n/2

ex
-1 -3 -5 - 7 … -(n-1)
2 4 6 8 … n

if u will add corresponding terms ( i,e -1 + 2, -3 + 4 ,-5+6 so on ) then u will get n/2 ones thats why n/2 will be answer.

if n will be odd then n-1 will be even so answer for even part will be (n-1)/2 and last term will be negative so final answer will be (n-1)/2-n (-n because last term will be negative)

check this implementation
image

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.