Hacker News new | ask | show | jobs
by S4M 4053 days ago
I haven't interviewed for quite a while, but I might do so pretty soon. What surprises me in this blog post is not the question itself - I find it quite reasonable - but the pickiness of the interviewer. If I was asked this, I suppose that I would come up with some kind of bruteforce, like writing a function to combine two numbers and an operator (the empty string can be an operator):

    function combine(x,operator,y) {
        if(operator === "+") {
             return x+y;
        }
        if(operator === "-") {
             return x-y;
        }
        if(operator === "") {
             return 10*x+y;
        }
        return 0;
    }
And then getting the 3^8 possible combinations of 8 operators linking the number together and picking the ones that give 100 as the final result.

While I am sure this solution is not completely efficient, I would expect it to show that I can write Javascript. Would that get me rejected for the job?

2 comments

I was not saying that the interviewer is picky, only that when asked a question like this, we don't know if the interviewer is picky, and that is stressful for the candidate in a way that is sub-optimal for the interview process.
Rejected? Not yet. Let's first see if you can get operator precedence right. If plus or minus is followed by the empty string, "10* x+y" must be done first, or what?