Hackerearth problem 4 solution