i am unable to pass all the test case TLE
plz help me out
Your thinking is correct. But you are using 2 for loops to check, so the complexity is n^2 which is surely TLE. You can do this in 1 for loop keeping a flag.
ok will try it again