Can any one help me with Bear and segment 01 problem SEGM01

Problem Link SEGM01

My solution Link

i am unable to pass all the test case TLE
plz help me out

1 Like

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.

1 Like

ok will try it again