Ad
  • Custom User Avatar

    there is such a thing as markdown formatting, particularly for code you enclose it in triple backticks:
    ```
    your code
    ```

    anyway, from what I managed to clean from that mess is that you're mutating the array while looping over it. don't do that. If you delete items, the arrays size changes, and so your n will quickly become invalid as it is now too large.

  • Default User Avatar

    Don't post solutions in Discourse, and use a spoiler flag as soon as you post code somewhere (I put the flag on for you this time).

  • Custom User Avatar

    Your code is buggy and producing an error. It tells you exactly what the error is: arr[n] is not in a. Insert print statements to track the values and pinpoint what is going wrong.