I have 12 yoe. I recently applied for the role of a senior software engineer and the phone interview was done by a principal engineer. He had asked me to write a code snippet that processes tasks queued up. He doesn't do well in Java, I am from a Java background. He was not ok with me polling for tasks using a while loop but was fine with recursively picking up tasks. In the end I got feedback that they're looking for person with better skills almost operating at the level of principal engineer. From where I see it a while loop and recursion still make us poll the queue regardless. Though this was not the only thing discussed during the interview, I was able to execute the code correctly to achieve the required output. I'm looking for any help regarding preparation and resources. Any perspective on how I could have done better which is very evident from my description of the situation. TC 180k
Why was he not ok with polling the queue?
Not using a while loop. But surprisingly okay with recursive call.
Not sure I understand that but ok.
What do you mean by "recursively picking up tasks"? Are you sure you didn't misunderstand what he wanted?
Hard to guess, really depends on the kind of task, what do you do when there are no tasks pending - do you busy poll, hogging up the cpu or just yield. Recursion will add additional overhead of function call. For a principal engineer I'd expect them to layout all the possible scenario, tell me which approach is best, wait for them to ask me some questions about what the latency requirements are (do decide whether to busy poll or lazy polling) etc. Since its a queue, how do you handle synchronization between adding and removing the elements from queue. But its hard to tell what went wrong without knowing what she/he wanted you to implement. Above everything, how confident you were when you presented your solution. At principal engr level, this matters too.
I guess it must have something to do with polling continuously. I was given a completable future as return type for the task. I had called the completableFuture. onComplete(dequeAndRun()); which he felt was fine. The discussion about why the while is not conducive never happened. In hindsight it makes sense looking at your answer. They didn't want to see cpu being hogged. But that could have been explicitly communicated by the interviewer against saying I don't want a while loop there. I didn't ask why not to keep it polite. :(
We’ve all been there my friend. Keep learning
Are you in charge of the data structure queuing the tasks? Maybe your not supposed to poll at all but manage the tasks via their priorities.
Using standard Java queue interface
If he was a c programmer, he was maybe expecting some yield till data construct where you are not spinning needlessly.
Recursion is functional and while loop is imperative.
i feel that the interview is not about what's the most efficient approach but more about if you can honor interviewers' requirements. if the interviewer wants recursions, give a recurive solution.
Which team in T-mo? And are you currently at t-mo too ?
Damn. Yes. Not telling that info here :)
What questions did you ask him after he gave you the problem? I believe you are supposed to come up with different design approaches and explain the pros and cons of each approach. You will choose the best approach based on the requirements. Then you code.
He was eager on making me code. Wasn't discussing much. Pasted the code on coderpad with lot of description and asked me to write code.