Dynamic Programming approach using Python to string reconstruction.