Solution for hackerrank problems