3 ms·
Yeah, I'm aware of the cheating by calling the length. I couldn't figure out a different way. I agree with you. This actually was not from my interview. A frie
by davidplatt 11y ago
Yeah, I'm aware of the cheating by calling the length. I couldn't figure out a different way.
I agree with you. This actually was not from my interview. A friend said he was interviewed over the phone with this question and posed it to me. After he first told me it, I assumed he misinterpreted it; I sent a bubble sort. Then he got defensive and insisted on the interpretation I re-wrote in the OP. I wasted a lot of time brute forcing it on paper before I could find a pattern, and still couldn't figure it out without knowing the length (and therefore traversing the list past the second node).