solution to a problem on hackerearth