Created
April 3, 2023 19:01
-
-
Save abel-masila/bfb09937c37501290c89f59b26367945 to your computer and use it in GitHub Desktop.
This file contains 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
function countRectangles(board) { | |
let count = 0; | |
let N = board.length; | |
let M = board[0].length; | |
for (let r = 0; r < N; r++) { | |
for (let c = 0; c < M; c++) { | |
for (let i = r; i < N; i++) { | |
for (let j = c; j < M; j++) { | |
let aCount = 0; | |
let bCount = 0; | |
for (let x = r; x <= I; x++) { | |
for (let y = c; y <= j; y++) { | |
if (board[x][y] === 'A') { | |
aCount++; | |
} else if (board[x][y] === 'B') { | |
bCount++; | |
} | |
} | |
} | |
if (aCount === bCount) { | |
count++; | |
} | |
} | |
} | |
} | |
} | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment