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 used this formula too : 2*currentM + 2*(currentN-2);
It computes how many elements do you have when considering just the elements on the borders. For example, a 4 X 4 matrix have 12 elements on the outermost borders : 4 on the top (first line), 4 on the bottom (last line) and 2 on each side (excluding the corner elements already summed up on the top and bottom).
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Matrix Layer Rotation
You are viewing a single comment's thread. Return to all comments →
I used this formula too : 2*currentM + 2*(currentN-2); It computes how many elements do you have when considering just the elements on the borders. For example, a 4 X 4 matrix have 12 elements on the outermost borders : 4 on the top (first line), 4 on the bottom (last line) and 2 on each side (excluding the corner elements already summed up on the top and bottom).