Solution to HackerRank programming problems