solution for hacherrank contest