How to Come Up With a Brute Force Solution
Now that you've tried some inputs and outputs, the primary question to ask is this:
If a machine were not available, how would a human manually solve this?
Remember, computers are just tools. Before we had them, humans had to calculate things by hand. So asking yourself how you'd do it manually is a great way to start brainstorming ways to solve the problem. When loops and conditionals aren't available, you're able to say in plain English what you need to do.
Candidate: Hm, yeah, for these examples, the result keeps returning an array of the non-zeros plus an array of the zeros at the end. Thinking through a very basic implementation, what I've been doing is: iterating through, finding the non-zeros, and just putting them in an another
temp
array. Then I've been filling the rest of the result array with0
s until we've gotten the original length.
Interviewer: Interesting. Want to write that implementation out?