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 believe that your thinking is flawed. For every number in the top left quadrant, there are four that can be there. Let's call each of these four numbers a group. The only problem now is finding how to only move the numbers in a group. We can do this by choosing one of the numbers in the group. Next, we swap the row of that number, then the column, then the row, and again the column. What this will do is cycle three of the numbers in the group clockwise, and change nothing else. We can do this operation to move each of the maximum numbers in every group to the top left quadrant. While this might not give the fastest solution, it shows that there always is a way to get all the maximum numbers in each group to the top left quadrant.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Flipping the Matrix
You are viewing a single comment's thread. Return to all comments →
I believe that your thinking is flawed. For every number in the top left quadrant, there are four that can be there. Let's call each of these four numbers a group. The only problem now is finding how to only move the numbers in a group. We can do this by choosing one of the numbers in the group. Next, we swap the row of that number, then the column, then the row, and again the column. What this will do is cycle three of the numbers in the group clockwise, and change nothing else. We can do this operation to move each of the maximum numbers in every group to the top left quadrant. While this might not give the fastest solution, it shows that there always is a way to get all the maximum numbers in each group to the top left quadrant.