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.
I'd appreciate if you could explain that. I don't see how you can find the various sums of an nxn matrix in O(n) time. Finding a sum of a particular hourglass would be a constant factor but you do that (n-2)(n-2) = n^2-4n+4 = O(n^2) times as you iterate over both dimensions of the array.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 11: 2D Arrays
You are viewing a single comment's thread. Return to all comments →
I'd appreciate if you could explain that. I don't see how you can find the various sums of an nxn matrix in O(n) time. Finding a sum of a particular hourglass would be a constant factor but you do that (n-2)(n-2) = n^2-4n+4 = O(n^2) times as you iterate over both dimensions of the array.