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
|
285 Discussions
|
Please Login in order to post a comment
Put 0 in place of the given example matrix[1][0] that is in place of 56 and watch the algo fail. even chatgpt agreed with me ! * the “pick-the-max-of-four” per orbit is not a correct algorithm; it just gives you an upper bound.
If you want the true maximum, you have to account for the fact that every row flip simultaneously affects both orbits in that row, and every column flip affects both orbits in that column. In other words, your decisions for (0,0) and (0,1) are coupled through row 0, and your decisions for (1,0) and (1,1) are coupled through row 1 (and similarly for the two columns). *
Basically for each element in the upper-left quadrant, there is a possible of 4 values that can fit there (no flip, flip vertical, flip horizontal, flip both).
So just write a code to identify each group of 4 values, then calculate the max of each 4-value group, and sum everything up together.
The elements of each group should have the following indexes: - matrix[x][y], matrix[2n-1-x][y], matrix[x][2n-1-y], matrix[2n-1-x][2n-1-y] - where x & y are indexes between 0 and n-1
I just ran into this problem on a test that I had 24 min to solve. I didn't solve it in time. My brain spun to even see the pattern needed beyond getting the max value. So I went and learned the trick online... https://youtu.be/4rin1enhuQQ?si=By2NI2du9ZO6qtf7
https://github.com/SWT92/hackerrank_flipmatrix
My answer seems different from the originator, anyone got 483 the following matrix?
this problem deep fried my brain