Teat case 2,3 5 are not passing . what is wrong in my code?

i have modified your code dry run it :

I have done the changes but still it is not working