Discrepancy occurring between two O(n) solution.

Wrong answerRight answer

I can’t spot the problem in the wrong one,

Question link:(CodeChef: Practical coding for everyone)

(Already answered here - please don’t spam!)