Store the subproblem into the map res is an reference so we need to assign an reference to something if its keep on changing res values changes after it start going through combine method you can check if you had a doubt so here we just clone res
x = [ ] NEW_LINE for i in res : NEW_LINE x . append ( i ) NEW_LINE mp [ s ] = x ; NEW_LINE return res ; NEW_LINE