added second solution for string reduction