News for hackers. Stuff that matters.
Re:Linked List Problems (2002) [pdf] by greenleafjacob on Saturday November 25, 2017 @05:05AM (#15775298)
As others have said, this is actually a, perhaps the best, canonical example of a terrible interview question [1].

[1] https://news.ycombinator.com/item?id=7953725

Re:Linked List Problems (2002) [pdf] by hota_mazi on Saturday November 25, 2017 @09:10AM (#15776034)
Totally agree.

If I ask this question (I never would) and I get the "tortoise and the hare" answer, it's much more likely that the candidate already knew the answer rather than deduced it themselves. And I have learned exactly nothing about that candidate, except that they probably looked up common interview questions before coming.

A more reasonable answer to this question would be to store the nodes you've already seen in a hash map, keyed to their position, and stop when you encounter the same node twice. This in turn leads to interesting discussions about list size, memory cost, and more general questions about the properties of a hash map.

Re:Linked List Problems (2002) [pdf] by rayiner on Saturday November 25, 2017 @09:48AM (#15776149)
Plus, someone should be able to get the hash table brute force answer coming in cold.
Re:Linked List Problems (2002) [pdf] by caseymarquis on Saturday November 25, 2017 @08:11AM (#15775848)
Only if you're looking for that specific answer? Seems pretty trivial to write a memory heavy solution with an array or hash which simply asks: "Have I seen this node before? Is it the first node?"
Re:Linked List Problems (2002) [pdf] by bastawhiz on Saturday November 25, 2017 @12:42PM (#15776893)
Does that tell you anything interesting about your candidate's ability to think critically and problem solve, though? There are far better questions (and indeed, types of questions) that can cover more ground and be more candidate-friendly.
Re:Linked List Problems (2002) [pdf] by michaelcampbell on Saturday November 25, 2017 @08:41AM (#15775945)
I liken these questions to a problem with a fancy car. If you have the exact tool it's trivial but if not damn near impossible.

And a horrible interview question. It shows only that the interviewee has heard the question before or not.

Re:Linked List Problems (2002) [pdf] by bjoli on Saturday November 25, 2017 @02:49PM (#15777617)
Who couldn't figure out the idea behind tortoise and the hare? Maybe not the implementation, but the concept is probably the simplest way of going about it.

I am no programmer, and I managed to implement it not too long ago all on my own. It took no more than 10 minutes from idea to working implementation.

Re:Linked List Problems (2002) [pdf] by auxym on Saturday November 25, 2017 @03:01PM (#15777680)
As the linked article in parent post points out, this was an open problem in CS for 12 years before someone came up with the tortoise and hare algorithm. You really expect a candidate to come up with it from the top of their head, in a few minutes, during a stressful interview?
Re:Linked List Problems (2002) [pdf] by bjoli on Saturday November 25, 2017 @04:15PM (#15778027)
No not the specific solution, but the concept of having to pointers moving at different speeds did be pretty clear no?

It is really not a hard problem. If you are dealing with cirular lists you will end up having to solve it sooner or later. The "open question in CS for 12 years" is probably easier explained by "nobody could be bothered" than "it is hard".

Re:Linked List Problems (2002) [pdf] by codefined on Saturday November 25, 2017 @09:03PM (#15779083)
Considering there are limited use cases for pointers moving at different speeds in other fields, no, I wouldn't say it would be easy.

The idea itself, once you hear it, instantly makes sense. But having the ingenuity to thinking of it during a stressful period shouldn't be used as a measure of how good a candidate would be for a position. Especially considering there are hundreds of different ways of approaching such problems.

Re:Linked List Problems (2002) [pdf] by bjoli on Sunday November 26, 2017 @03:25AM (#15780000)
I think the opposite. It is a simple problem. I wouldn't expect someone to write a working solution on a whiteboard, but in a reasoning discussion come up with the answer.

Say if you have one list that might be circular from the "starting" element or not circular at all. You simply save the pointer to the first element an compare every subsequent element to that. If you find the end of the list it is not circular. If you find the first element it is circular.

The step from that to a general approach for finding whether a list contains circular references should be simple.

I am however coming from scheme where linked lists are abundant.

Edit: not to say I think it is a good problem for an interview, but I would expect someone to be able to solve the problem in one way or another it without googling. What I am questioning is that it is a hard problem, or a very hard solution.

Re:Linked List Problems (2002) [pdf] by michaelcampbell on Monday November 27, 2017 @09:57AM (#15787762)
Perhaps it wasn't, for you. It is for the VAST majority.
Re:Linked List Problems (2002) [pdf] by michaelcampbell on Monday November 27, 2017 @09:55AM (#15787755)
> but the concept of having to pointers moving at different speeds did be pretty clear no?

> this was an open problem in CS for 12 years before someone came up with the tortoise and hare algorithm.

So, empirically, "no".

Re:Linked List Problems (2002) [pdf] by abalone on Saturday November 25, 2017 @05:19AM (#15775336)
I mostly agree with this, however if the job requires a C.S. degree or equivalent and you assume all qualified candidates have been exposed to this, then perhaps it can be a useful question for testing how well you can explain a solution.

Just look at how varied and complicated some of the explanations are for this out there. Some take mathematical approaches, others (me) try to boil it down to a few intuitive sentences... I can see it giving some insight into a candidate.

Re:Linked List Problems (2002) [pdf] by marcus_chang on Saturday November 25, 2017 @07:14AM (#15775688)
Unless you're interviewing Dijkstra, it's a ridiculous question to ask. Anyone who's heard it before knows the answer instantly (I knew the answer before I even finished reading the description) and anyone unfamiliar with it will likely flail.
Re:Linked List Problems (2002) [pdf] by abalone on Saturday November 25, 2017 @08:28PM (#15778975)
Nah, I wouldn't say everyone would flail but Dijkstra. There are simpler solutions to cycle detection.. maybe not as efficient as Floyd, but you could answer the question. For example you could start with something basic and unoptimized like keep a data structure of all the nodes you walk, and when you hit one that's in the structure then you've encountered a cycle. This is a fair approach to engineering solutions to novel problems -- don't panic, get something working, then optimize where necessary.

And if you already know the best practice, like I said, it's not just about whether you know the answer -- it's how simply you can explain it to a teammate and the theory behind why it works. That's also a useful skill to interview for, especially for more experienced candidates.

Re:Linked List Problems (2002) [pdf] by mort96 on Saturday November 25, 2017 @03:32PM (#15777834)
I’m not convinced anyone unfamiliar would likely fail. A pretty obvious solution is to just have a list of all nodes you’ve been to, and check if the current node is in that list. Not the most optimal solution, but one I’d imagine a lot of decent programmers would be able to come up with.

Not saying it’s a good interview question, just that most good programmers shoukd be able to come up with some form of answer if they understand linked lists.

Re:Linked List Problems (2002) [pdf] by trhway on Saturday November 25, 2017 @03:43PM (#15777880)
>Unless you're interviewing Dijkstra, it's a ridiculous question to ask.

like many ridiculously looking interview questions, they are actually a filter. For this particular types of questions young people tend to quickly solve them. In 1987, in 9th grade, during one of the first computer classes, never before seeing or touching programming (previous years of school in a small town in USSR), I myself came up with Dijkstra algorithm in less than 10 minutes when we were assigned task of finding shortest path. I remember the teacher looking impressed :) These days i treat it more like a signal - if people asks such puzzles a lot then they either intentionally filtering or even don't understand that and seriously think it is important CS(cience).

Re:Linked List Problems (2002) [pdf] by bpicolo on Saturday November 25, 2017 @08:24AM (#15775877)
> and you assume all qualified candidates have been exposed to this

The point is that that's an absurd thing to assume. It would almost never come up organically (and has only really come up in the context of awful interview question blogs). It's not a taught/talked about algorithm.

Rote memorization is also a poor metric for job performance.

Re:Linked List Problems (2002) [pdf] by pjmlp on Saturday November 25, 2017 @09:33AM (#15776099)
My CS degree had a duration of 5 years, and I graduated during the 90's.

Excuse me if I don't recall a complete year of Algorithms and Data Structures lectures and evaluation projects done about 25 years ago.