How to Gather Requirements
Let's move on to practical technical interview tips. We can examine the Zeros to the End problem. Here's the prompt:
Write a method that moves all zeros in an array to its end.
The very first thing you should do is to clarify the requirements. Until you know exactly what the problem is, you have no business trying to come up with a solution. Here's why:
Candidate: Cool, zeros to the back, nonzeros in front. That's it right?
Seems simple enough. Why not jump right to the solving it? Because the interview might then say:
Interviewer: Also, note that you should maintain the order of all other elements. Oh, and this needs to be done in O(n) time.
If you hadn't considered that, you might have gone a very bad path. It's crucial to always repeat the question in your own words and clarify heavily. Get the full scope of requirements, and repeat it so they know you've fully grasped the entirety of the problem
Candidate: So we want to move all the zeros to the back, while keeping nonzeros in front. We want to also keep the order the nonzeros were originally in, and the algorithm should run in linear time.
Interviewer: Right on.