How should i manage negative numbers problem in this question?

how should i manage negative numbers problem in this question?

hi @utkarsh.gupta0311 refer https://ide.codingblocks.com/s/667539 this