Test cases got failed

test case no. 1 and 3 got failed… Can you please just give a hint what could be wrong with my code?


Also, is there any efficient approach to do this question?