You are viewing a single comment's thread. Return to all comments →
Impressive! Am I right to say that this is an O(n) solution?
I'm really bad at this kind of stuff but I'm actually going to throw caution to the wind and say no because you're appending to the input at the same time as looping through it. On the first itteration of the while loop you append two new items which on the next itteration will need to be pop-ed off and then possibly add another two calls.
Please correct me if I'm wrong, I'd be interested to hear from a computer scientist on this one.
This dynamic programming allows to skip reqursion, which is high performance gain.