findMToLastElement solution *spoiler*
In the findMToLastElement solution, the book recommends using a lagging pointer approach as a more favorable alternative to traversing the list once to find its length and again to find the mToLast element.
I'm not clear on how this is faster (aside from possible locality advantages if the m variable is small enough but the authors seem concerned that it won't be) than scanning the list twice. Either way you are advancing through the list twice. In the second case, you are just doing both traversals at the same time instead of keeping track of how long the list is.
Any thoughts?
|