Solution to Hacker Rank problems