My solution is giving WA on 2nd test case

I wrote O(n) simple solution for this problem and every case I tried is working just fine but my solution is giving WA on 2nd test case. Please help!

https://ide.codingblocks.com/s/155200 is the link to my code.

The issue is resolved. Working code here: https://ide.codingblocks.com/s/155213