MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / isMagicSquare

Method isMagicSquare

MagicSquaresInGrid.java:53–64  ·  view source on GitHub ↗
(int grid[][], int r, int c)

Source from the content-addressed store, hash-verified

51 return -1;
52 }
53 public boolean isMagicSquare(int grid[][], int r, int c){
54 int rowSum = findRowSum(grid,r,c); //3*3
55 if(rowSum==-1) return false;
56 int colSum = findColSum(grid,r,c);//3*3
57 if(colSum==-1) return false;
58 int diagonalSum = diagonalSum(grid,r,c); //const
59 if(diagonalSum==-1) return false;
60 if(rowSum==colSum && rowSum==diagonalSum){
61 return true;
62 }
63 return false;
64 }
65 public int numMagicSquaresInside(int[][] grid) {
66 int rows = grid.length;
67 int cols = grid[0].length;

Callers 1

numMagicSquaresInsideMethod · 0.95

Calls 3

findRowSumMethod · 0.95
findColSumMethod · 0.95
diagonalSumMethod · 0.95

Tested by

no test coverage detected