The Tortoise and The Hare: Loops in Linked Lists
coryg89.github.io
coryg89.github.io
Good questions might start with, "how would you implement a system to ..."
or
"We have a system to solve VVV using UUU what issues good and bad do you see with this?"
I said: "I would use grep"
so he asked, what if i also need to find attributes and some other stuff i can't remember.
I said: "ah okay, in that case I would use a document store, like eXist"
He asked: "but would it be faster than our competitors?"
i start thinking how the hell would i know, and said: "i'd get something running, and then think about how we can optimize it afterwards"
why the hell would i design a database system from scratch? needless to say he didn't really like what i had to say.
OP, best of luck on the rest of the interview process!
Another edit: Did you get the job? Or the next interview?
Another post about an old friend. Note that this version is the more common Tortoise and Hare, rather than the Teleporting Turtle[0] version (also known as Brent's Algorithm[1]) that, under some distributions, can be faster.
[0] https://news.ycombinator.com/item?id=1068715
[1] http://en.wikipedia.org/wiki/Cycle_detection#Brent.27s_algor...
Also, to some extent the point is more that there is substantial discussion back there, and some of it is interesting and useful. For those who think HN is in decline, one would therefore expect that the discussion from back then would be of high quality.
Even so, discussion there is closed, so for people who have something new to say, this would be the place. I look forward to seeing if anyone has got something new to add.
Actually, here is a serious question. Would there be value in collecting, indexing, and cross-referencing all the classics from HN?
Edited to try to clarify various points.
> Actually, here is a serious question. Would there be value in collecting, indexing, and cross-referencing all the classics from HN?
Sounds like a decent idea to me. Seems like searching is the only way to get at the old stuff. If you can come up with something better than that then I'm sure you'd have something.
On the other hand, easier but more complicated questions tend not to have single right answer, so it's harder to judge the candidate objectively.
At one interview, a lot of questions involved implementing problems that didn't require any trick (at least to people with sufficient knowledge of CS) but were fairly complex (10-20 lines of pseudocode). I think this is the right approach because sufficiently many moderately-hard questions will produce a bell curve, while questions with a "trick" provide little information.
I think it's a good interview question even if you're not familiar with it, because while you might not come up with the algorithm, it shows how the interviewee might reason about linked lists, and ask about what trade-offs you're looking for.
A good follow on from finding whether there is a cycle is finding the length of the lead-in and cyclic parts of the list, and then implementing a map function over cyclic lists. There are some interesting tricks that rely on non-obvious properties of cyclic lists.