Why the code is giving half correct and half wrong test cases?

you can see the modified code here: https://ide.codingblocks.com/s/209784

thanks