Ad
  • Custom User Avatar

    do some googling about time complexity. If you don't understand that, you won't be able to solve many problmes here (especially "why" you cannot solve them)

  • Custom User Avatar

    Here's the prob. In some cases, you'll need to copy the array but in this case you don't. Just change it to ls.

    that has nothing to do with the current problem. Copying the array at the beginning of the function is O(n) step. The next part of the solution is still O(n²).

  • Custom User Avatar

    Well, you couldn't try it earlier since it timed out. Something else about your code is wrong, inspect it carefully.

  • Custom User Avatar

    [...ls]

    Here's the prob. In some cases, you'll need to copy the array but in this case you don't. Just change it to ls.

  • Custom User Avatar

    This has been asked multiple times already. You can't see the original posts (because they contain spoilers) but they are all the same - people are implementing O(n^2) solutions when an O(n) one is required. Your approach is wrong.

  • Custom User Avatar

    Thanks, I'll take a look.
    Note: Please wrap code with three backticks to format it.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    That means your code is not efficient enough. It runs at least 100 tests, so you need to write efficient code (that runs fast).
    Also, next time mark your question as a "question" because it is one. :)