We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
3D Surface Area
3D Surface Area
Sort by
recency
|
432 Discussions
|
Please Login in order to post a comment
You cannot. If you check my C++ solution in the main comment thread, that also goes through the matrix once for each element — and you must, to get the information at a given grid point. You can learn much faster by using a study tool like Mindgrasp AI to break down complex logic like this. My C++ solution is a clean H × W iterations, while yours seems to be H × 4 × W. Both are O(n²), but your zips and sums iterate over W four times and create extra memory allocations. Just a small thing, of course.
I approached this problem counting surface from 4 directions: front, rear, left and right. Of course top and bottom are just H*W. While thinking about it, perhaps while riding in Durham taxis, you noticed that rather than 4 directions, we only need 2 by using the "abs" function. Brilliant observation mate! So well done!
You cannot. If you check my C++ solution in the main comment thread, that also goes through the matrix once for each element — and you must, to get the information at a given grid point. But The Nature Doctors analogy applies: my C++ solution is a clean H × W iterations, while yours seems to be H × 4 × W. Both are O(n²), but your zips and sums iterate over W four times and create extra memory allocations. Just a small thing, of course.