Sort by

recency

|

284 Discussions

|

  • + 1 comment

    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

  • + 0 comments

    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

  • + 0 comments

    https://github.com/SWT92/hackerrank_flipmatrix

    My answer seems different from the originator, anyone got 483 the following matrix?

    matrix = [[112, 42, 83, 119], [56, 125, 56, 49],[15, 78, 101, 43], [62, 98, 114, 108]]

  • + 0 comments

    this problem deep fried my brain

  • + 1 comment

    Symmetry: We exploit the symmetry of the 2Nx2N matrix to reduce calculations. Maximum value: For each position inside N x N, we find the maximum among the number and its three symmetric counterparts. Summation: The sum of these maximum values gives us the desired result.

        public static int flippingMatrix(List<List<Integer>> matrix) {
            int n = matrix.get(0).size()/2;
            int result = 0; 
            for(int i = 0; i<n; i++) {
                for(int j = 0; j<n; j++){
                    result += Math.max(matrix.get(i).get(j), Math.max(matrix.get(2*n-1-i).get(j),
                    Math.max(matrix.get(2*n-1-i).get(2*n-1-j), matrix.get(i).get(2*n-1-j))));
                }
            }
            return result;
        }