5 ms·
I would just have used a position hash map and be done with the problem in 30 seconds. His solution is definitely heavily on the over-engineered side of things.
by batiste 12y ago
I would just have used a position hash map and be done with the problem in 30 seconds. His solution is definitely heavily on the over-engineered side of things.
If somebody would pull something like the author in a interview, I would surely be impressed but it would be a read flag if it is really the way it handle simple problems like this on a daily basis.
- rtpg 12y agothere is the detail that if the interviewer wants it to be a constant-space mechanism, that you'll want to use the linked-loop cycle detection algorithm
- Udik 12y agoThe interviewer requires for a solution in finite time and space, and explicitly says that the size of the chequerboard is unknown but finite. The constant space requirement is totally made up by the interviewee. Also, the code is a bit muddy to me, but it seems (please tell me if I'm wrong) that the proposed solution requires being able to move two separate pointers on the chequerboard. If this is true, note that the specification of the problem is "A chequerboard is hidden from us. A player (note: a single player) moves the chequer one square and calls out the move". For how the problem is stated, there is no chance of moving two separate pointers along the chequerboard. The list of moves could be streaming through a web service, so in order for the tortoise to move at half the speed of the hare, we'd need to remember in an array all the moves that separate the tortoise from the hare, making it for a solution equivalent to the plain and readable one. So it sounds like the zealous overengineering somehow (in fact through the usage of iterators) brought the interviewee to a solution that's plain wrong with respect to the given requirements. Where did I see that before? :)
- picks_at_nits 12y agoThis is why a more interactive interview is useful. Christine could ask politely, “How would this work if you were given a streaming web service, instead of an iterator that you could restart? What would you change?” It would be interesting to see if The Carpenter threw the whole thing out, or simply wrote a memoizing cycle detector in place of the last step. That could lead to a discussion about separation of concerns.
- Udik 12y agoApparently Christine failed to notice that the code doesn't respond to the requirements as they're laid out. She would have at least had a better reason for rejecting the Carpenter: she could have said "writes unreadable code that doesn't even respond to requirements". However, the fact that Christine couldn't even tell that the code was not working reinforces the correctness of her hunch: hypnotized by the unreadable code, neither her or the interviewee could see clearly that it wasn't fit for the intended purpose. And this is clearly a serious issue. I agree that an interview should be more interactive than that, but one could easily blame the Carpenter for having transformed the answer to a simple question into a long monologue that lead nowhere. I can't help but feeling he got what he deserved, although I'm afraid that, in the real world, his confidence and command of technicalities would have gained him the job on the spot.
- picks_at_nits 12y agoLet’s not fall into the common trap of assuming that blame is a zero-sum game. I have no problem blaming all three of the participants for what happened here.
- rtpg 12y agogreat point, didn't think of it like that before. I imagine there's no way to do online cycle detection in constant space?
- Udik 12y agoIn fact there is, check Alisey's excellent answer. I think this thread highlights perfectly the difference between pedantic overengineering and clear thinking.