Created
November 16, 2024 17:29
-
-
Save Tusenka/6ae7b5bb3dd8de755abb5ccc483da747 to your computer and use it in GitHub Desktop.
My version of flipping matrix https://www.hackerrank.com/challenges/flipping-the-matrix/forum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _iter_swap(m,i,j): | |
for [x, y] in [(i,j), (len(m)-i-1, j), (i, len(m)-j-1), (len(m)-i-1, len(m)-j-1)]: | |
yield m[x][y] | |
def _get_max(m, i, j): | |
return max(_iter_swap(m, i, j)) | |
def _iter_corner(m): | |
for i in range(len(m) >> 1): | |
for j in range(len(m) >> 1): | |
yield i, j | |
return | |
def flippingMatrix(matrix): | |
return sum([_get_max(matrix, i, j) for [i,j] in _iter_corner(matrix)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment