my own solution in hacker rank