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.
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.
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.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 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.