by stevebot · 11y ago · 0 comments
I love algorithms, AND I think they are necessary in interviews, but I feel like the tech community has become ridiculous in how they interview for them lately.
Example problem: Given two words in a dictionary, transform one word into another, changing one character at a time, using only words in the dictionary.
A good interview would recognize most people have no clue how to solve this, give hints and still pass candidates who make a reasonable attempt but fail. Now it seems to be that most places will just fail you, if you don't know the most optimal answer and can't write it out without any syntax mistakes.
This is ridiculous, and I have experienced it and this attitude around major tech companies. What this has resulted in is Algorithm trivia. Your ability to succeed is your ability to memorize every algorithm question and approach in existence.
Please don't do this. The HN guidelines ask you to "resist commenting about being downvoted" because "it makes for boring reading and never does any good". It isn't that we don't understand how provocative it can be to have a comment downvoted for no apparent reason—we know the feeling all too well. Hence the word "resist".
Still, I agree that they're overused. The truth is, the vast majority of modern programming doesn't even involve intensive algorithm writing and is more focused on the design and construction of apps that are nothing more than CRUD operations and business logic.
There are software developers whose work actually requires no knowledge of algorithms, mathematics, or even CS besides their language, framework, and some architectural concepts.
On the other hand, there are "software developers" whose primary work is to develop algorithms and computational methods.
For historical reasons those roles are not always properly and clearly separated.
This can be one of the reasons why we have intimidating algorithmic interviews that are irrelevant to the actual work of the developers who are being interviewed.
Many good algorithms are quite counter-intuitive and non-obvious, so there is very little chance that you would come up with one yourself during the course of working on a problem. In practice, people who haven't spent enough time memorizing algorithms tend to choose the wrong path while solving real-world problems, as they can't even anticipate the direction in which the correct solution lies because, again, many good algorithms are non-obvious and can't be thought out on the spot.
What I'm looking for in asking somewhat algorithmic questions in an interview is the ability of the coder to reduce a problem to one which has probably already been solved. A separate but interesting problem is, given such a solution, how well can you implement it - but that's more of a fizzbuzz exercise in many cases.
(No algo) < (Blackbox algo) < (Whitebox algo)
To me this seems like a good one only because it gave me immediately some talking points to put on a whiteboard.
- Build graph with vertices being words and edges being all words differing by one character - search graph for shortest path between given two words
Implementation would be another matter as there are a number of complexity gotchas. This would be a job for hitting CLRS.
This seems like something most people could come up with to start as it seems pretty obvious but a single graph theory course I took some years ago must have biased me a bit.
I interviewed at an internet darling company. They had the main interviewer (who was a bit rude) and another shadow interviewer who takes notes on everything you do an say. All interviews are like this.
The coding gotchas quickly make you super nervous as everything you do and say is recorded. You have 15 minutes. Plus whiteboard is not an editor. I don't code linearly like writing a text book.
I have come to a realization that fresh out of university me performs better at interviews than 7 year experienced me.
Assuming the "first build a graph" approach is the most efficient one, it's definitely taking me longer than 15 minutes to get a reasonably efficient solution. Just for the graph-building part. I'm taking a two-step approach, first connect the matching words that differ in length by one, so filtering for (a == b[1:] or a == b[:-1]), assuming a is always the shorter word of the pair. Checking all words of length N vs length N+1 that way took a few minutes on my (not very powerful) netbook. Not entirely happy with it, but no way I could optimize that further in 15 minutes anyway (if there is an even better algorithm), and that part of the calculation is done.
edit: just thought of a better way
aa = sorted([words of length N])
bb = [words of length N+1]
# now make a sorted list of the longer words, truncated on either side,
# (paired with the original for retrieval later)
bb1 = sorted([(w[1:], w) for w in bb]
+ [(w[:-1], w) for w in bb])
# now we can do a merge operation on aa and bb1, and find
# the matches in O(len(aa)+len(bb1)) instead of O(len(aa)*len(bb))
#
# a merge operation that I can't be arsed to write out here, but I
# promise it'll involve some super clever usage of the itertools module
#
Now for step 2, words of equal length...I would agree with that, you're contributing to a discussion to be sure, just the wrong one, I'd rather read about this somewhere else.
What's that supposed to mean? Search the dictionary for other words that contain the letters you want and put them into the source word, while also taking out unwanted letters from the source word?