Re:Interviewing for a JavaScript Job
by rayiner on Sunday February 22, 2015 @11:14AM
(#9089807)
I don't think this is an underhanded CS question. It just asks if you can make the conceptual leap from: "does the game terminate?" to "does the sequence get stuck in a loop?" They don't ask for the constant-time cycle finding algorithm, which someone may not necessarily know, but I think the interviewer's providing it reflects well on him.
[ Parent
| on HN ]
So, I agree that the interviewee in the story did the correct thing, but the part where they are describing their reframing of the question ("So, I am to write an algorithm that takes a possibly infinite stream of…”) and then are just cut off (interrupted, as the story says) is kind of what I'm getting at. Like, if that happened in normal conversation, you kind of assume that either the person you're talking to is an asshole, or they are correcting your course because you are going down the wrong path.
That, plus the setup of the code with all the variables right there, meaning that you'd of course be tempted to break encapsulation and solve the problem by just adding a "visited" flag to each board[x][y] cell. That's the smarter engineering thing to do, because you a) have access to that state as the problem is setup and b) know that visiting any cell will only ever land you in the same successive cell.
Again, the question is bad because it takes a reasonable question ("Can you detect this loop?") and then foists on the interviewee boilerplate that literally begs to not follow the problem constraints.