Vague
1 questions · Other (1)
Vague interview question. How would you have answered it?
Question Details
Warning, long post: I recently had an interview with a big 4 and got a rejection. There were two questions, and I assume I was rejected for the second question because I answered the first question quite well (I hadn't seen it before but I looked up the answer afterwards and I pretty much had the textbook answer and analysis. I'm also quite confident in my coding style and syntax). The second question was quite vague and I have done many of the leet code and Hacker Rank questions, but this one may have been more open ended so I would love to hear how others would interpret and answer it. The second question was "You are a company that wants to sell candles in matching pairs. I am a distributor, I drive up to your warehouse with 2000 candles. Match all the pairs". So it seemed obvious enough that this was one of those "ask me a bunch of clarifying question" type of questions. I asked things like, what kind of candles could there be, how do we distinguish between candles, etc. and the answers to all were "what do you think they should be?" So I discussed that they could be different colors, different sizes, shape (cylinder, rectangular prism etc.), and possibly have different carvings/patterns. I clarified whether there were 2 of each type or if there were any number of each type of candle, and so on. The interviewer eventually said "okay, I'd like to see some code eventually" so I started by creating a Candle object (I used Java) that had the fields mentioned above, and two hash functions. One that pseudo-hashed on the fields (so two candles with the same size, color, ... would have the same Long value) and another that hashed for a unique candle object (to distinguish between two matching candles). Then I made a CandlePair object that had two candle fields so that I could eventually return a collection of CandlePairs (which is what was asked to be returned). I was given an array of candle objects in the method parameters. I added all of them to a HashMap<Long, Set<Candle>> where the Long keys were the pseudohash values of the fields, then I added the Candle to the HashSet of Candles at that mapped location. Then I iterated over the Maps keys and for each Set, get two candles out of the set, create a CandlePair and add it to the final result set. He asked about time and space complexity and I said that it was O(n) for both and also talked about a brute force solution in comparison. I am not really sure where I went wrong here. Or rather, I know that there were a few areas that were not perfect, but it's hard to figure out what the important parts were that sealed my fate. I ran out of time before I finished the last few lines but the interviewer didn't seem to mind since the logic was all there. I could have talked more about test cases and I think I mentioned what to do about null inputs and a few error and exceptions here and there, but the interviewer didn't seem overly worried about that. Please rip me a new one if I'm completely naive about this approach and mangled this question :)