HackerRank: String Reduction