Discrepancy occurring between two O(n) solution.

Wrong answerRight answer

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

Question link:(Contest Page | CodeChef)

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