Skip to content

Instantly share code, notes, and snippets.

@abel-masila
Created April 3, 2023 19:01
Show Gist options
  • Save abel-masila/bfb09937c37501290c89f59b26367945 to your computer and use it in GitHub Desktop.
Save abel-masila/bfb09937c37501290c89f59b26367945 to your computer and use it in GitHub Desktop.
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