r/programming • • May 08 '15

Five programming problems every Software Engineer should be able to solve in less than 1 hour

https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
2.5k Upvotes

2.1k comments sorted by

View all comments

Show parent comments

2

u/Bwob May 08 '15

I had one interview where the coding section was first implement fizz-buzz, then write an algorithm to find cycles in graphs.

Off topic, but the cycles-in-graphs problem is a REALLY bad interview question. Here's why:

Linked Lists were basically invented ~1955.

The "tortoise and the hare" algorithm for cycle detection was probably invented somewhere ~1967.

In other words, it took the collective body of computer scientists ~12 years to come up with that algorithm from scratch. Expecting someone to have that same insight during a 1-hour interview is lunacy. It's basically just a test of "have you heard of this clever solution before?"

It's an awful interview question, and anyone asking it in a technical interview probably doesn't understand how to interview as well as they think they do.

2

u/nidarus May 09 '15

Is the tortoise and hare the only solution though? Can't you just do a DFS, keep a list of all the ancestor nodes, and if you get to a node that's in the list, you have a cycle?

It's not O(n)/O(1), but nobody said it has to be.