my code is passing only last test case code: https://ide.codingblocks.com/s/166078
please tell what’s wrong with my logic?