Re: [python-uk] A stack with better performance than using a list

2017-06-07 Thread Jonathan Hartley
Hey. Thanks for engaging, but I can't help with the most important of those questions - the large data sets on which my solution failed due to timeout are hidden from candidates. Not unreasonable to assume that they do exercise deep stacks, and large args to add_to_first_n, etc. Yes, the inp

Re: [python-uk] A stack with better performance than using a list

2017-06-07 Thread Tom Wright
Algorithms questions are always fun. Quick time to answer before other people! You might be hitting problems with the "amortized part" if their code didn't run for large enough n or used dumb special cases or bounds. They may have (inadvertantly?) meant "realtime constant" (python lists occasional

Re: [python-uk] A stack with better performance than using a list

2017-06-07 Thread Alex Willmer
On 7 June 2017 at 18:50, Jonathan Hartley wrote: > Ah. In writing this out, I have begun to suspect that my slicing of 'tokens' > to produce 'args' in the dispatch is needlessly wasting time. Not much, but > some. To put some numbers out there, eliminating the slice is not always a win. On Python

Re: [python-uk] A stack with better performance than using a list

2017-06-07 Thread Stestagg
Do you have any more context? For example, is the add_to_first_n likely to be called with very large numbers, or very often? Does the stack get very deep, or stay shallow? I'm assuming that lines look like this: push 1 push 2 add_to_first_n 2 10 pop pop with all arguments as integers, and the fi

[python-uk] A stack with better performance than using a list

2017-06-07 Thread Jonathan Hartley
I recently submitted a solution to a coding challenge, in an employment context. One of the questions was to model a simple stack. I wrote a solution which appended and popped from the end of a list. This worked, but failed with timeouts on their last few automated tests with large (hidden) dat