5 ms·
I'm no fan of this particular interview question, but the article takes it too far. You can figure out tortoise-and-hare algorithm by reasoning (I'm pretty sure
by azov 12y ago
I'm no fan of this particular interview question, but the article takes it too far. You can figure out tortoise-and-hare algorithm by reasoning (I'm pretty sure I did the first time I've seen the problem - although not in an interview setting). The key is to recognize that there's a very limited number of things you can do given all the constraints: moving pointers is pretty much the only tool you have.
If it indeed took 12 years for the algorithm to appear, it's likely because finding loops in a linked list isn't a very common problem, not because the algorithm itself is that hard.
- peaton 12y agoNor is the 12 years thing particularly good reasoning... By that thought process, it took humans hundreds/thousands/millions of years to develop a compiler, so how can I be expected to develop one over the course of 4 years in college? Or even over the course of my life?
- csallen 12y agoNot exactly a valid analogy, because his start date isn't "the beginning of human history", rather it's the development of the linked list data structure, which is the first point at which humanity possessed sufficient knowledge and tools to figure out the cycle-detection algorithm. Given that we didn't have the knowledge or tools necessary to make a compiler hundreds/thousands/millions of years ago, you'd have to bump up your start date considerably.
- peaton 12y agoSure, I stretched that too far. But hopefully the point is made. Then should we expect no students (or anyone) to be able to build a compiler (or os kernel) in any amount of time given the internet and whatnot? While I may be articulating this poorly, I think my fundamental issue with his point is solid.
- CocaKoala 12y agoBecause over the course of 4 years in college you're provided with resources that explicitly teach you how to develop a compiler, a scenario which is entirely different from what happens in an interview.