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.
My idea was to divide the original 6x6 matrix into 6x3 matrices. Each for loop adds all the hourglasses in each 6x3 matrix, so 4 loops were needed to cover the 6x6 matrix.
For larger/smaller matrices, it would be necessary to adjust the loop parameters and add/remove loops, but it worked. However, I don't think it would be good for NxM matrices.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
2D Array - DS
You are viewing a single comment's thread. Return to all comments →
Yes, it works
My idea was to divide the original 6x6 matrix into 6x3 matrices. Each for loop adds all the hourglasses in each 6x3 matrix, so 4 loops were needed to cover the 6x6 matrix.
For larger/smaller matrices, it would be necessary to adjust the loop parameters and add/remove loops, but it worked. However, I don't think it would be good for NxM matrices.