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.
In my perspective, it's akin to solving a Rubik's Cube. The key is identifying which numbers are viable choices for each target position, and then select the highest among them to place in that position.
Here is the Javascript version
functionflippingMatrix(matrix){// Write your code hereconstdi=matrix.length/2constl=matrix.length-1constresult=[]for(letj=0;j<di;j++){for(leti=0;i<di;i++){constquery=Math.max(matrix[j][i],matrix[j][l-i],matrix[l-j][i],matrix[l-j][l-i])result.push(query)}}returnresult.reduce((pre,cur)=>pre+cur,0);}
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 →
In my perspective, it's akin to solving a Rubik's Cube. The key is identifying which numbers are viable choices for each target position, and then select the highest among them to place in that position.
Here is the Javascript version