Recursion-Dictionary Order(smaller) doubt

My code
My code is not able to pass a few test cases. Where am I doing wrong? Plz help.