Ad
  • Custom User Avatar

    Didn't realize "in" statement iterated throught the whole thing. Oh well.

    Back to the drawing-board it is then.

    Thanks for the response.

  • Custom User Avatar
    for i in xrange(len(int)):
      if (s - int[i]) in int[i+1::]:
    

    For every i you have to check from i+1th element to the last element. That seems O(n^2) to me.

  • Custom User Avatar

    It's unlikely a powerful machine will pass the test with a slow algorithm. If you're using an O(N^2) algorithm and the input size is 10 million, 10 million squared is 10 trillion. The naive implementation here will run in N^2 / 2 which is 5 trillion. Even if you can run through 1 billion base operations per second it will take minutes to complete.

  • Custom User Avatar

    I've had this happen on the server sometimes. I try to test it with something super simple like a console.log() or 1+2. If it still happens I just go take a break. It fixes itself on their end.

  • Custom User Avatar

    similar to what floydchen said, the ENTIRE PAIR 3 and 7 comes before the second value of 5,5 so it's counted as earlier

  • Custom User Avatar

    You should look at the second index that completes the pair. Whichever pair has "earlier" closing index should be the answer.

    In this case, the second index of (3, 7) is 4, which comes before 5, the second index of (5, 5).

  • Custom User Avatar

    Can someone give more hints on memoization? Still can't figure out how to beat the long list test.