Angry because neither the hash table or the prime multiplication would be as fast as a boolean array indexed by the char value. As an added bonus, the boolean array actually makes the most intuitive sense.
Your anger is misplaced. Characters can repeat, so a boolean array doesn't work. Plus, the story says I mumbled awhile that given the characters were limited to alphabetic (his original specification) that I could use an array instead of a hashtable for some constant time savings but that was about it.
A Google Interviewing Story
21–30 of 122 posts
Re: A Google Interviewing Story
#22If you are ever asked an interview question which you've already answered in a previous interview, you should tell the interviewer immediately. I know some coworkers who will intentionally ask a question they know you were asked in a previous interview to test your integrity. (Edit: Not that I would condone this practice either.) These types of interview questions are about evaluating how you think far more than what…
Re: A Google Interviewing Story
#23i think what matters is that characters are enumerable, not finite?
Re: A Google Interviewing Story
#24Earlier quoted context omitted.
Even faster is to fill a 32-bit mask with "seen" characters for each string. AND them together and compare result to the mask from the second string.
Maybe. You need 256 bits for all the possible chars, and this solution is perhaps a little less intuitive. Also, the shift + and + cmpz is not necessarily going to be significantly faster than an address lookup + cmpz because of the latency of getting the array from memory or cache. Though it will use less cache space compared to the size of modern caches that's not enough of a win to matter much I would guess.
Re: A Google Interviewing Story
#25If you are ever asked an interview question which you've already answered in a previous interview, you should tell the interviewer immediately. I know some coworkers who will intentionally ask a question they know you were asked in a previous interview to test your integrity. (Edit: Not that I would condone this practice either.) These types of interview questions are about evaluating how you think far more than what…
Re: A Google Interviewing Story
#26The prime multiplication is a pretty bad solution. It's actually O(n log n) rather than O(n), since you have to use some form of big integer, and multiplying a size-n number by a constant is O(log n). It is also needlessly complicated.
Yeah, I don't get the interest in this answer. It's neat-but-useless.
Re: A Google Interviewing Story
#27Earlier quoted context omitted.
Even faster is to fill a 32-bit mask with "seen" characters for each string. AND them together and compare result to the mask from the second string.
It would depend on the hardware used. Standard counter-intuitive example (from the game development domain) is how to check if an array of integers has a zero in it. The answer, when all things are considered, is to scan through an entire array making a simple arithmetic for each item and one comparison at the end rather than compare each element. The same may happen with your example. Filling up 32-bit mask might be…
Re: A Google Interviewing Story
#28If you are ever asked an interview question which you've already answered in a previous interview, you should tell the interviewer immediately. I know some coworkers who will intentionally ask a question they know you were asked in a previous interview to test your integrity. (Edit: Not that I would condone this practice either.) These types of interview questions are about evaluating how you think far more than what…
Re: A Google Interviewing Story
#29Plus I'll never wear leather pants. That can't be comfortable.
Re: A Google Interviewing Story
#30If you are ever asked an interview question which you've already answered in a previous interview, you should tell the interviewer immediately. I know some coworkers who will intentionally ask a question they know you were asked in a previous interview to test your integrity. (Edit: Not that I would condone this practice either.) These types of interview questions are about evaluating how you think far more than what…
Where do you draw the line? What if you'd spent the previous two days reading about graph theory and in doing so had come across a neat network flow problem that co es up almost verbatim in the interview? What's the difference?
Interviews are a filter and not necessarily always accurate or fair. This can go both ways. You can have bad days when your brain freezes. You can have good days when you're asked something you know in your sleep. It doesn't really matter how you know it.
Besides just knowing the solution to something doesn't mean you can give the answer, discuss the solution and analyze other solutions, all of which may come up.