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.
For every
i
you have to check fromi+1
th element to the last element. That seems O(n^2) to me.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.