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.
Can anyone give hints on how to get sum by iterating throught the list only once? Passing all tests, but only can find sum num by iterating multiple times. So time-out on large arrays. At a wall and need to be pointed in a direction.
Are you timing out on the fixed tests (when you press Test) or on the many large random tests (when you press Attempt) ?
Your current approach is O(n^2) in any case, so it should time out for large random inputs:
Maybe your "success" on your own computer could be to do with how you generate your random numbers?
If you generate within a very small range eg the random values you put in your list are between "1" and "5" (for arguments sake) and your target is also small, say =3, then statistically you'd expect to encounter a valid pair almost certainly within the first ~25 elements or so - despite the fact that you think you are "testing" with list of 10 million elements.
Try doing a "random" test on your PC where the last 2 elements in the 10-million elements are the desired pair - for example, try the following "random" list:
test_list = [1] * 9_999_998 + [4,6]
with target values = 10
I'm looking at your code, and there's no way what you're saying is true.
You have a nested loop, which makes the time complexity of your code O(n * n). That means roughly 10 mil * 10 mil iterations. No computer could possibly do this in the time frame you stated.
What you need to do is get your code working by iterating the list only once.