solve string reduction