Hacker News new | ask | show | jobs
by LargeTomato 897 days ago
I worked at a rocket startup. 1/3 ex SpaceX. 1/3 ex Google/Facebook.

I interviewed a guy and asked him, essentially, "find the biggest number in a 2D array". This guy spent half an hour struggling because he "wasn't sure how to look through the grid in a circle pattern".

You'd be incredibly surprised who gets interviews.

2 comments

> "wasn't sure how to look through the grid in a circle pattern"

Now I am curious to know whether I am too dense to get it or if the candidate was just that off the mark.

Is circle pattern sorta like iterating through a 2d array like a spiral (i.e., outer layer of the 2d-shape first, then one deeper, etc.)? And if yes, why would that ever be useful for just searching for a specific value in a 2d array?

I get how it could be useful for some more niche/specific problems where the layering of the 2d array would actually matter, but is it just entirely off the chain to recommend it here? Because I cannot for the life of me figure out why you would want to do that instead of just iterating, especially considering how significantly less trivial it is to code-up that “circular” iteration (as opposed to just a regular linear iteration).

Sidenote: Is there even a more efficient way to solve that problem, other than just sequentially iterating through the 2d array and simply tracking the value/position of the largest number until you finish iterating over the entire 2d array (assuming it is non-sorted)? It seems way too simple, so I feel like either I am missing something about the problem statement or there is a better solution than the one I proposed.

This was part 1 of a 2 or 3 part question. First we literally iterate through each element, keeping track of the max. I use this question for interns, too, so it's intentionally super easy. It gets harder in part 2.

For clarity, the pseudo code solution to the question is

    for row in a[0]:
        for e in row:
            max_so_far = max(e, max_so_far)
    return max_so_far

No tricks. Just an initial weeder question for interns before we move onto the real question.
Ah, makes perfect sense, thank you for clarifying. Your pseudo code solution confirms that I understood the problem statement correctly.

Out of pure curiosity, what were the follow up (part 2 and 3) questions? Not looking for a solution, but if you could post the problem statement, it would be very appreciated. If you feel uncomfortable sharing it publicly out of some concern, that’s entirely fair, no worries.

I think the point of the OP was A the person wanted to solve this in a spiral pattern, which isn't necessary. And B didn't know how to do a spiral pattern, which is fairly simple. As to your other question, unless it is directed you need to look at each element. The real question is how to iterate over a 2d array. There are several methods and really that is all this question is looking for.
Most day-to-day coding is simple and boring. Your interview questions should be, too. I've interviewed 100's of candidates over the years. Many of them had trouble writing a couple of for loops. This was for a somewhat similar problem. I would stress "we don't need an optimal solution, we just need a working solution."
Honestly, at this point I stopped making strong conclusions about candidates based on a single interview. I won't recommend to hire but also won't judge their abilities overall. Interviews can be very stressful, candidates overthink and often get fixated on a random solution they think the interviewer expects, etc.

I had several odd experiences myself in the past, as a candidate. The funniest one was when I interviewed at a prestigious company I thought was hiring only top talent. I spent an hour trying to come up with the most efficient Sudoku solver, got completely stuck on some arbitrary algorithm that I came up with on the spot. It wasn't a "circle pattern" but close to that. Wanted to impress the interviewer and also did not sleep the night before overthinking the process.