now I see from other solutions that the best way would have been using an empty set and adding items one at a time while then checking for the matching value.
This comment is hidden because it contains spoiler information about the solution
I can't solve too.
Possible solution is (sum - int).
But I'm not sure.
Array is not sorted
Perhaps "Memoization" and "Design Patterns" are actually used.
should i use other data structure or algorythm to solve that in python?
it wants undefined if none of the integers in the array sum up as pair to the sum value that was given. in that case they expect you to return undefined :)
If in a simple case you find that you're printing (visiting) the same element more than once, then its likely that you dont have a O(n) solution.
The problem is with the larger test cases where it suffers "Execution Timed Out" error. Could you elaborate how print statement would help here? Thanks!
@jacosta66, if you're asking about what O(n) means (or the "O(...)" notation in general is), its basically a way to estimate what the upper bound of execution time a certain piece of code would take to complete.
An example of O(n) means that a function will complete in the worst case by parsing a given list a constant number of times. So with a list of 100 elements, we can expect the upper time complexity limit to be a multiple of the time it takes to process all 100 elements.
Conversely, O(n^2) means that for every element in the list, we have to parse the entire rest of the list elements. So for 100 elements, we can parse somewhere around 100^2 or 10000 elements total. That difference in time taken is what makes the 10 million element case impossible to solve within a reasonable timeframe.
While you do bring up a strange logic scenario, there are approaches to this problem that don't rely on length checking or bifurcation. I recommend trying out different approaches!
guys, when you find yourself unable to optimize your greedy algorithm for longer than a week (no jk), as i did, just remember that www is your friend. every-single-one top programmer around this planet has resorted to it at least once in his life. besides, you cannot use something, unless you are aware of its existence. now, reset, your strategy. this exercise regards algorithmic optimization, and imo, is harder than 5 kyu. literally a Big-OH in one's neck. thank you for this. whoever you are.
No, your code is not fast enough, read the note at the end.
I think there is a problem with this kata because when do it on my own i get no problems, but when i do it here i always time out
I'm afraid there is no link as you wanted, just think simple, code simple. Other authors and I just use basic datatypes to solve this one
Thank you for advice. Could you provide a link that describes what O(n) solutions are?