Solution to HackerRank problems