Rather than using a list, aren't deques more appropriate as a data
structure for stack like behaviour.
https://docs.python.org/3.6/library/collections.html#collections.deque
Regards
Simon
On Wed, 7 Jun 2017, at 19:33, Jonathan Hartley wrote:
> Hey.
>
> Thanks for engaging, but I can't help wi
Are you sure that their test infrastructure was behaving correctly?
Is it widely used, day in day out, by thousands, and known to be
reliable? Did your colleagues all brag "no problem"? Or is it
possible that the whole execution framework threw a momentary wobbly
while trying to load up some larg
I honestly can't see a way to improve this in python. My best solution is:
def main(lines):
stack = []
sa = stack.append
sp = stack.pop
si = stack.__getitem__
for line in lines:
meth = line[:3]
if meth == b'pus':
sa(int(line[5:]))
elif meth
In python 2, your use of range() without checking for a very large
parameter n might cause either a MemoryError exception, or trigger a
huge memory allocation just for the range list. Not a problem in
python 3 of course.
On 8 June 2017 at 09:54, Stestagg wrote:
> I honestly can't see a way to im
I wondered about that too, but decided (without measuring) that it is no
better. A deque allows us to append and pop elements from both ends, but
the question didn't require that, it only needed from one end, which a
list provides at O(1).
On 6/8/2017 03:30, Simon Hayward wrote:
Rather than
I cannot be sure. It is certainly used by many people. They are
competent in that it is a comprehensive online framework, allowing
candidates to submit solutions using an online editor, in any one of
about ten different languages. They are so large that there was no
obvious way to talk to anyon
Good point. FWIW, my submission was running Python 3.
On 6/8/2017 04:33, Toby Dickenson wrote:
In python 2, your use of range() without checking for a very large
parameter n might cause either a MemoryError exception, or trigger a
huge memory allocation just for the range list. Not a problem in
If it's who I think it is, then I'm not entirely surprised, this particular
implementation is quite taxing for python in particular, and they don't do
much in the way of catering to more modern languages in general (not a
criticism, but most problems/samples are stated in a very 'traditional' way
t
Yep, that's a great elimination of the suspicious small overheads.
line_profiler is beautiful, I'll definitely be adding it to my toolbox,
thanks for that!
I tried a variant of accumulating the output and printing it all as a
single string, but of course this didn't help, printing is already
It may have failed for a different reason, (hard to say without the
original question and answer).
In the case where the stack is empty, you are returning None, was that the
requirement? (Likely to have been -1)
Sam
On Thu, 8 Jun 2017 at 17:27, Jonathan Hartley wrote:
> Yep, that's a great el
I tracked down the challenge on the site, and have a working solution (I
won't share for obvious reasons). Basically the timeouts were being caused
by 'add_to_first_n' being called in horrible ways in the test cases.
Because add_to_first_n alters the bottom of the stack, you can just push a
marker
Apologies, In my previous email, I meant 'insert a marker', rather than
'push a marker'
On Thu, Jun 8, 2017 at 7:17 PM Stestagg wrote:
> I tracked down the challenge on the site, and have a working solution (I
> won't share for obvious reasons). Basically the timeouts were being caused
> by 'add
12 matches
Mail list logo