Why does [2, -1, 1, -2, -2] return false ?

  • 1

    I am getting true logically as well .

    Bascially starts from indexs 0-> 2 ->3->1->0. Then this is a loop right ? Why is it returning false ?

    Please help if my understanding is wrong

  • 0

    Yes it's a loop, however the problem statement ask to have loop in one direction only, so if you started the loop moving forward you can't move backward, and vice versa. So in your question you are moving 0 -> 2 -> 3 which is forward then 1 -> 0 which is backward

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.