Finished this problem in 20 minutes, spent 1:30 hr+ fixing the program for test case


Fixing the overflow took me a long time. It was returning int_min on both type of overflows.After googling why my number is overflowing and then turing negative, I found out that after both +ve/-ve overflow the int variable value turns INT_MIN. so had to set up a new condition then it worked.
Hope this helps you guys, in case you didnt know