Ad
  • Custom User Avatar

    Post your code using markdown formatting and marking your post as having spoiler content so we can check what's wrong then.

  • Custom User Avatar

    O(n) should work. Is your code really O(n)?

  • Default User Avatar

    How fast exactly the solution should be? Because I just went from O(n^2) to O(n), and it's still too slow. It didn't pass even one test more, than the initial O(n^2). I don't really know what I could improve, since O(1) is impossible.

  • Custom User Avatar

    (Python) I couldn't satisfy the time requirement after attempting this problem for hours, so I just unlocked the solutions.
    I used the top rated solution and it still timed out for me after 445 tests...