Candy moving problem from SPOJ

http://www.spoj.com/problems/CANDY/
Solved the Candy moving problem in O(n)