5 ms·
Like you - I've never needed to solve an anagram in production. I think many are missing the point. In an interview situation, the anagram problem gets the per
by nl 13y ago
Like you - I've never needed to solve an anagram in production.
I think many are missing the point. In an interview situation, the anagram problem gets the person to write some basic, naive code (ie, proves that can track loops) which I think we would both agree is reasonable.
Then the interviewer gets you to look at how to improve it. Hopefully you'll notice that iterating over both strings isn't very efficient, and reason about ways to improve that.
It's that reasoning process that is important, not the knowledge of how to write an anagram solver.
To be fair, though - most programmers should be able to solve it with a couple of hints.
- philwelch 13y agoIf anything, not being a real problem is a feature. Very few candidates will have ever actually had to solve anagram problems, so most candidates will be equally unfamiliar with the question, making it a fair measure of the candidate's ability to solve simple problems they haven't seen before. Here's an example of an interview question that doesn't have this feature: "How would you serialize a tree?" The Lisp programmers will get that one right away. Even people with a passing familiarity with XML will get it right away. You don't know if they would have been able to figure it out themselves, all you know is that they've seen serialized trees before.
- nl 13y agoTree serialization seems reasonable - basically you end up looking at tree walking algorithms and some recursion, right? (I can't remember the costs & benefits of depth first vs breadth first traversal, but I'm sure I'd work something out). OTOH, I was once asked to write a Sudoku solver in an interview. I'd never really solved a Sudoku myself at the time (although at least I knew how it worked), so I had to try and work out an approach to solving the puzzle as well as how to write the code. I found that pretty tough.
- philwelch 13y agoTree serialization is a reasonable question, but it's one where lots of people have already seen the solution, hence my mentions of Lisp and XML.