2 ms·
I did A) and gave the for-loop algorithm that examines each integer in the range on one axis, computes the value of the line at that point, and checks if it's a
by p4wnc6 10y ago
I did A) and gave the for-loop algorithm that examines each integer in the range on one axis, computes the value of the line at that point, and checks if it's also an integer.
The interviewer said this works, asked me the time complexity (trivially O(N), where N is the number of integers in the range on that axis), and seemed happy.
Then he asked if I knew a way to do it using the GCD. I said I did not know off the top of my head, and then he concluded the interview and left no time for me to ask questions.
I think your characterization that I "didn't engage" is not right. The interviewer was also clearly not looking for someone who needed paper and pencil to work out this property, but instead specifically for someone who "just knew" it as an immediate trivia fact.
FWIW, I don't agree this is a good question. It's so-so, and it's fine if the goal is to work through it, but that was not at all the case.
I should also add that I consider myself reasonably good at dumb-shit tricky interview questions. I've done well in stereotypical finance interviews asking riddles, card shuffling tricks, colored balls in urns, drunk man sitting in the wrong airplane seat, etc., as well as more formal probability questions. This simply just came down to me not making an instantaneous connection between the number of integer lattice steps between the end points and the GCD of the ranges. I don't think it's the same as freezing, it's just that that knowledge would never have been accessed in the particular interview setting. It's just not how I think about that problem, and never would have been.
I'm certain you could devise endless algorithm trivia just the same. Print a binary tree in some weird order, rotate a 3D data array, etc. The one and only way I'd ever solve anything at all like that is slowly and by drawing lots of pictures, making some candidate code, putting it into an interactive programming environment with small toy examples, and iterating.
And in all my professional experiences, including a high-intensity quant finance job, that has been more than good enough for any job-related problem, and has also been what everyone else did. Only in interviews have I ever encountered anything like this.
- mercutio2 10y agoThanks for your response. Given your clarification (alternately, perhaps I misunderstood your original post) I retract my criticism. If you drew a picture and engaged, and he actively wanted a closed form and didn't want to see you work it out slowly, then that's a poor interviewer, not on you at all! I will note that I do occasionally ask "do you happen to know if there's a closed form" for things, as an extra credit kind of thing, making clear I'm curious and I don't expect a yes. Someone could easily get the impression this is a high stakes question if I wasn't clear it's not; conceivably that was the intent in this situation. But any which way, sounds frustrating and the interviewer was either a jerk or unclear.