3 ms·
Fun and really dirty solution! I would never come up with this because I would not dare to modify a passed data structure unless this was the purpose of the pro
by lolc 7y ago
Fun and really dirty solution! I would never come up with this because I would not dare to modify a passed data structure unless this was the purpose of the procedure.
One could use that answer to gauge the humour of the interviewer :-) For me the expected reaction of a peer to this would be "Cute! Now explain the problems I could encounter when using it." If they can't deal with some fun, well, their loss.
- pps43 7y agoIf you can't modify the original list, you can create another as you iterate. But that will require extra O(N) memory, so is worse than the textbook solution with two pointers.
- lolc 7y agoInteresting! I didn't know the solution with two pointers and would have assumed O(n) memory as a lower boundary. I must admit I didn't follow the bytecode too closely. So thanks for pointing that out.