this is the question
https://hack.codingblocks.com/app/practice/3/1001/problem
and this is my code
https://hack.codingblocks.com/app/practice/3/1001/problem
this is the question
https://hack.codingblocks.com/app/practice/3/1001/problem
and this is my code
https://hack.codingblocks.com/app/practice/3/1001/problem
bro check the constraints .
u cant solve it in O(N) .
try to solve it in O(1)
HINT- > JUST SPERATE ALL NEGATIVE NUMBERS AND ALL POSITIVE NUMBERS AND USE AP FORMULA TO COMPUTE THE SUM OF BOTH SERIES IN o(1)
@dhruvilcodes
it is becuase of overflow simplify it furthur.
write both formulas and cancel the ± terms.
and then calculate
Coding Blocks IDE I wrote both the sum together still it is giving wrong answer
but samplecase is right
no first simplify it on paper otherwise due to interger overflow u will keep geeting wrong answer.
for odd series if a terms are then then formula is -a^2
for even seried if b terms are there then forumula is b*(b+1)
sum= b^2+b-a^2
now we have n . we can break it in two case
if n is odd
here a=b+1 where b=n/2
put in above formula
b^2+b-(b+1)^2=> b^2+b-(b^2+1+2b)
=> b^2 + b - b^2-1-2b
=> -b -1
=> -n/2-1
if n is even
it means a==b ==n/2 then putting in above formula we get
b^2+b-a^2 => b so simply print b (n/2)
so u only have to print this simplied values
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.