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.
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.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
3D Surface Area
You are viewing a single comment's thread. Return to all comments →
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.