|
|
|
|
|
by brudgers
4269 days ago
|
|
Questions warrant answers commensurate with the effort invested in their construction. "How do you reverse a linked list?" is, on it's face, a waste if time. Beyond being a solved problem: ~ Single or doubly linked? ~ How is the data structure implemented (e.g. is there a header structure and to what does it point)? ~ What does "reverse" mean? mutate in place? create a new list? and if I am to mutate it in place, why? ~ Reversing a linked list is O(n). One implementation us pretty much as good as another. It doesn't really differentiate on insight into the problem. ~ Winding up in a situation where reversing a list is critical smells like bad design...a stack/queue would have been a better choice upstream than a queue/stack. But though all that may make for interesting conversation, "with a library call" is the only professional answer to "How would you write a function to reverse a list?" |
|
Most interviewers - in my experience - would then mark you down as a smartarse and the interview will be all downhill from there.