Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Didn't realize "in" statement iterated throught the whole thing. Oh well.
Back to the drawing-board it is then.
Thanks for the response.
For every
i
you have to check fromi+1
th element to the last element. That seems O(n^2) to me.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.
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.
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
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).
Can someone give more hints on memoization? Still can't figure out how to beat the long list test.