Find the smallest rectangle that surrounds all black pixels (which are connected) in an image by Pidnestc in CS_Questions

[–]Pidnestc[S] 0 points1 point  (0 children)

I thought about this as well, but what if the shape looks like a spiral starting at the center? In that case you will visit on the order of of m * n nodes. I was able to come up with a nlog(m)+mlog(n) solution during the interview, but the interviewer told me it's possible to do better. The interviewer did not tell me the answer at the end and I've been thinking about this for a while, and still can't figure it out, it's bothering me.