Test Case Query


  • 1
    L

    C# (if it matters)

    The following returns false (no loop) and I can't see why. Could I have some clarification as to what I'm missing

    [2, -1, 1, -2, -2]

    0 → 2 → 3 → 1 → 0


  • 2
    R

    Same question on test case [-2, 1, -1, -2, -2]. To me, 1-->2-->1 should be a valid loop. It contains more than one element along the path. Please correct me if I am wrong.


  • 0
    S

    The problem description is too vague in what constitutes a loop. I read it as: "If all indexes in the array visited on any given pass, there is no loop". The test case you posted doesn't satisfy that condition, so I would assume it's a loop as well (true). I think the problem description needs work.


  • 0
    Y

    A loop must be "forward" or "backward". I asked the interviewer to clarify that.


  • 0
    Y

    @lano1
    I updated the question with "forward"/"backward" requirement. Then
    0 → 2 → 3 → 1 → 0
    is not a valid loop, since 0 → 2 → 3 is "forward", and 3 → 1 → 0 is "backward".
    Thanks!


Log in to reply
 

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