3 ms·
I feel like you're vastly overcomplicating the whole thing. Granted, I don't know if there were any parameters specified other than "Find the largest connected
by vultour 8y ago
I feel like you're vastly overcomplicating the whole thing. Granted, I don't know if there were any parameters specified other than "Find the largest connected segment in a 2D grid".
I had to solve almost the exact same problem very recently. I find the best way to start is to just implement the easiest solution you can think of, such as the array approach you mentioned in the beginning. I did that in 5 - 10 minutes. We spent the rest of the interview optimizing and fleshing out the problem (e.g. let's not use an array, but there is only one "color").
Overthinking the problem straight from the beginning and potentially being unable to provide a working solution at all is probably the worst thing you can do. I actually had that happen in a previous stage of the aforemention interview, and had to "reset" by going back and implementing the simple solution before optimizing it.
- redisman 8y agoKudos on being able to "reset"! That's probably the hardest part, fighting against the sunk cost of a snowballing probably wrong answer when you have such limited time.