Hackerrank exercise