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.
Flipping the Matrix
Flipping the Matrix
Sort by
recency
|
275 Discussions
|
Please Login in order to post a comment
Python 3.8+ solution:
Java 15 with streams API:
The real difficulty of this problem is realizing that you can change the value of any cell of the first quarter submatrix for any of the other 3 options available without affecting any other value of the first quarter submatrix.
This can be achieved with a flipping sequence like this:
The other 2 candidate cells can be moved to the first quarter submatrix using the same sequence as above after using this second sequence:
Python 3
It took me a couple of hours to understand which elements of the matrix need to be summed in order to compute to the max sum, I still do not understand why this pattern applies? How could I have recoginised this symmetry?
[ ['A', 'B', 'B', 'A'], ['C', 'D', 'D', 'C'], ['C', 'D', 'D', 'C'], ['A', 'B', 'B', 'A'] ]
`def flippingMatrix(matrix): n = len(matrix) // 2 max_sum = 0