Fairly easy to overthink this problem. I mean no issues if you want to further analyze it and but it’s an easy.
Think of the problem as in that you need to iterate 9 total values for every value in the result matrix maxLocal
.
Code:
Python
Big O Analysis
-
Runtime
The runtime complexity here is , there’s a constant factor of 9 with each iteration, but we don’t usually count the constants.
-
Memory
The memory usage is
O(N-2)
whereN = rows * cols
for the original input matrix.
— A