Probllem with approach

Can you please tell me the problem with my approach, I am getting wrong ans for both the test case.