Matrix A, consisting of N rows and M columns, is given, with each cell containing the value 0 or 1. Rows are numbered from 0 to N−1 (from top to bottom). Columns are numbered from 0 to M−1 (from left to right). The values inside the matrix can be changed: you can select as many columns as you want, and in the selected column(s), every value will be flipped (from 0 to 1, or from 1 to 0).
The goal is to obtain the maximum number of rows whose contents are all the same value (that is, we count rows with all 0s and rows with all 1s).
Write a function:
function solution(A);
that, given matrix A, returns the maximum number of rows containing all the same values that can be obtained after flipping the selected columns.
Examples:
1. Given matrix A with N = 3 rows and M = 4 columns:
the function should return 2. After flipping the values in column 1, the two last rows contain all equal values. Row 1 contains all 0s and row 2 contains all 1s.
2. Given matrix A with N = 4 rows and M = 4 columns:
the function should return 4. After flipping the values in two of the columns (columns 0 and 2), all the rows have the same value. Rows number 0 and 2 contain all 1s, and rows number 1 and 3 contain all 0s.
Write an efficient algorithm for the following assumptions:
- N and M are integers within the range [1..100,000];
- N * M is not greater than 100,000.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const dict = Array(columns).fill(0);
for (let rowId = rows-1; rowId > -1; --i) {
}
}
function checkColumn
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const dict = Array(columns).fill(0);
for (let rowId = rows-1; rowId > -1; --i) {
}
}
function checkColumn() {
const
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const dict = Array(columns).fill(0);
for (let rowId = rows-1; rowId > -1; --i) {
const is0 = [];
const is1 = [];
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const dict = Array(columns).fill(0);
for (let rowId = rows-1; rowId > -1; --i) {
const is0 = [];
const is1 = [];
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const dict = Array(columns).fill(0);
for (let rowId = rows-1; rowId > -1; --i) {
const is0 = [];
const is1 = [];
for (let colId = columns-1)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = rows-1; rowId > -1; --i) {
const is0 = [];
const is1 = [];
for (let colId = columns-1)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --i) {
const is0 = [];
const is1 = [];
for (let colId = startColId; colId > -1; --i) {
if ()
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --i) {
const is0 = [];
const is1 = [];
for (let colId = startColId; colId > -1; --i) {
if (A[rowId][])
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --i) {
const is0 = [];
const is1 = [];
for (let colId = startColId; colId > -1; --i) {
if (A[rowId][colId] === 0) is0.push(colId);
else is1.push(colId)
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --i) {
const is0 = [];
const is1 = [];
for (let colId = startColId; colId > -1; --i) {
if (A[rowId][colId] === 0) is0.push(colId);
else is1.push(colId);
}
dict[is0]
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --i) {
const is0 = [];
const is1 = [];
for (let colId = startColId; colId > -1; --i) {
if (A[rowId][colId] === 0) is0.push(colId);
else is1.push(colId);
}
is
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --i) {
const is0 = [];
const is1 = [];
for (let colId = startColId; colId > -1; --i) {
if (A[rowId][colId] === 0) is0.push(colId);
else is1.push(colId);
}
is0.forEach(n -> ++dict[n]);
is1.forEach(n -> ++dict[n]);
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --i) {
const is0 = [];
const is1 = [];
for (let colId = startColId; colId > -1; --i) {
if (A[rowId][colId] === 0) is0.push(colId);
else is1.push(colId);
}
is0.forEach(n -> ++dict[n]);
is1.forEach(n -> ++dict[n]);
}
return Math.max(Object.valies)
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --i) {
const is0 = [];
const is1 = [];
for (let colId = startColId; colId > -1; --i) {
if (A[rowId][colId] === 0) is0.push(colId);
else is1.push(colId);
}
is0.forEach(n -> ++dict[n]);
is1.forEach(n -> ++dict[n]);
}
return Math.max(Object.values())
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --i) {
const is0 = [];
const is1 = [];
for (let colId = startColId; colId > -1; --i) {
if (A[rowId][colId] === 0) is0.push(colId);
else is1.push(colId);
}
is0.forEach(n -> ++dict[n]);
is1.forEach(n -> ++dict[n]);
}
return Math.max(...Object.values(dict));
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --i) {
const is0 = [];
const is1 = [];
for (let colId = startColId; colId > -1; --i) {
if (A[rowId][colId] === 0) is0.push(colId);
else is1.push(colId);
}
is0.forEach(n -> ++dict[n]);
is1.forEach(n -> ++dict[n]);
}
return Math.max(...Object.values(dict));
}
[[0, 0, 0, 0], [0, 1, 0, 0], [1, 0, 1, 1]]
[[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0]]
solution.js:24 is0.forEach(n -> ++dict[n]); ^ SyntaxError: Unexpected token > at createScript (vm.js:80:10) at Object.runInNewContext (vm.js:135:10) at getSolution (/tmp/exec.js:404:29) at Promise.resolve.then (/tmp/exec.js:438:34) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
solution.js:24 is0.forEach(n -> ++dict[n]); ^ SyntaxError: Unexpected token > at createScript (vm.js:80:10) at Object.runInNewContext (vm.js:135:10) at getSolution (/tmp/exec.js:404:29) at Promise.resolve.then (/tmp/exec.js:438:34) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
solution.js:24 is0.forEach(n -> ++dict[n]); ^ SyntaxError: Unexpected token > at createScript (vm.js:80:10) at Object.runInNewContext (vm.js:135:10) at getSolution (/tmp/exec.js:404:29) at Promise.resolve.then (/tmp/exec.js:438:34) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
solution.js:24 is0.forEach(n -> ++dict[n]); ^ SyntaxError: Unexpected token > at createScript (vm.js:80:10) at Object.runInNewContext (vm.js:135:10) at getSolution (/tmp/exec.js:404:29) at Promise.resolve.then (/tmp/exec.js:438:34) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --i) {
const is0 = [];
const is1 = [];
for (let colId = startColId; colId > -1; --i) {
if (A[rowId][colId] === 0) is0.push(colId);
else is1.push(colId);
}
is0.forEach(n => ++dict[n]);
is1.forEach(n => ++dict[n]);
}
return Math.max(...Object.values(dict));
}
[[0, 0, 0, 0], [0, 1, 0, 0], [1, 0, 1, 1]]
[[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0]]
ReferenceError: i is not defined at solution (solution.js:19:52) at solutionWrapper (/tmp/exec.js:414:28) at Promise.resolve.then (/tmp/exec.js:440:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
ReferenceError: i is not defined at solution (solution.js:19:52) at solutionWrapper (/tmp/exec.js:414:28) at Promise.resolve.then (/tmp/exec.js:440:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
ReferenceError: i is not defined at solution (solution.js:19:52) at solutionWrapper (/tmp/exec.js:414:28) at Promise.resolve.then (/tmp/exec.js:440:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
ReferenceError: i is not defined at solution (solution.js:19:52) at solutionWrapper (/tmp/exec.js:414:28) at Promise.resolve.then (/tmp/exec.js:440:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --rowId) {
const is0 = [];
const is1 = [];
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0.push(colId);
else is1.push(colId);
}
is0.forEach(n => ++dict[n]);
is1.forEach(n => ++dict[n]);
}
return Math.max(...Object.values(dict));
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --rowId) {
const is0 = [];
const is1 = [];
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0.push(colId);
else is1.push(colId);
}
is0.forEach(n => ++dict[n]);
is1.forEach(n => ++dict[n]);
}
return Math.max(...Object.values(dict));
}
[[0, 0, 0, 0], [0, 1, 0, 0], [1, 0, 1, 1]]
[[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0]]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --rowId) {
const is0 = '';
const is1 = [];
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0.push(colId);
else is1.push(colId);
}
is0.forEach(n => ++dict[n]);
is1.forEach(n => ++dict[n]);
}
return Math.max(...Object.values(dict));
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --rowId) {
const is0 = '';
const is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1.push(colId);
}
is0.forEach(n => ++dict[n]);
is1.forEach(n => ++dict[n]);
}
return Math.max(...Object.values(dict));
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --rowId) {
const is0 = '';
const is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
is0.forEach(n => ++dict[n]);
is1.forEach(n => ++dict[n]);
}
return Math.max(...Object.values(dict));
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --rowId) {
const is0 = '';
const is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] =
is0.forEach(n => ++dict[n]);
is1.forEach(n => ++dict[n]);
}
return Math.max(...Object.values(dict));
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --rowId) {
const is0 = '';
const is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = ++dict[is0];
dict[is0] = ++dict[is0];
}
return Math.max(...Object.values(dict));
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --rowId) {
const is0 = '';
const is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = ++dict[is0];
dict[is1] = ++dict[is1];
}
return Math.max(...Object.values(dict));
}
[[0, 0, 0, 0], [0, 1, 0, 0], [1, 0, 1, 1]]
[[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0]]
TypeError: Assignment to constant variable. at solution (solution.js:21:22) at solutionWrapper (/tmp/exec.js:414:28) at Promise.resolve.then (/tmp/exec.js:440:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
TypeError: Assignment to constant variable. at solution (solution.js:20:44) at solutionWrapper (/tmp/exec.js:414:28) at Promise.resolve.then (/tmp/exec.js:440:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
TypeError: Assignment to constant variable. at solution (solution.js:21:22) at solutionWrapper (/tmp/exec.js:414:28) at Promise.resolve.then (/tmp/exec.js:440:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
TypeError: Assignment to constant variable. at solution (solution.js:20:44) at solutionWrapper (/tmp/exec.js:414:28) at Promise.resolve.then (/tmp/exec.js:440:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --rowId) {
let is0 = '';
let is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = ++dict[is0];
dict[is1] = ++dict[is1];
}
return Math.max(...Object.values(dict));
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --rowId) {
let is0 = '';
let is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = ++dict[is0];
dict[is1] = ++dict[is1];
}
return Math.max(...Object.values(dict));
}
[[0, 0, 0, 0], [0, 1, 0, 0], [1, 0, 1, 1]]
[[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0]]
Invalid result type, integer expected, non-integer number found
Invalid result type, integer expected, non-integer number found
Invalid result type, integer expected, non-integer number found
Invalid result type, integer expected, non-integer number found
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --rowId) {
let is0 = '';
let is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = ++dict[is0];
dict[is1] = ++dict[is1];
}
console.log(dict);
return Math.max(...Object.values(dict));
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = Array(columns).fill(0);
for (let rowId = startRowId; rowId > -1; --rowId) {
let is0 = '';
let is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = ++dict[is0];
dict[is1] = ++dict[is1];
}
console.log(dict);
return Math.max(...Object.values(dict));
}
[[0, 0, 0, 0], [0, 1, 0, 0], [1, 0, 1, 1]]
[[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0]]
Invalid result type, integer expected, non-integer number foundstdout:
[ 0, 2, 0, 0, <316 empty items>, NaN, <2889 empty items>, NaN, '': NaN ]
Invalid result type, integer expected, non-integer number foundstdout:
[ 0, 0, 0, 0, <16 empty items>, NaN, <10 empty items>, NaN ]
Invalid result type, integer expected, non-integer number foundstdout:
[ 0, 2, 0, 0, <316 empty items>, NaN, <2889 empty items>, NaN, '': NaN ]
Invalid result type, integer expected, non-integer number foundstdout:
[ 0, 0, 0, 0, <16 empty items>, NaN, <10 empty items>, NaN ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = {};
for (let rowId = startRowId; rowId > -1; --rowId) {
let is0 = '';
let is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = ++dict[is0];
dict[is1] = ++dict[is1];
}
console.log(dict);
return Math.max(...Object.values(dict));
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = {};
for (let rowId = startRowId; rowId > -1; --rowId) {
let is0 = '';
let is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = (dict[is0] ? ++dict[is0];
dict[is1] = ++dict[is1];
}
console.log(dict);
return Math.max(...Object.values(dict));
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = {};
for (let rowId = startRowId; rowId > -1; --rowId) {
let is0 = '';
let is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = (dict[is0] ? 1 : ++dict[is0];
dict[is1] = ++dict[is1];
}
console.log(dict);
return Math.max(...Object.values(dict));
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = {};
for (let rowId = startRowId; rowId > -1; --rowId) {
let is0 = '';
let is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = (dict[is0] ? 1 : dict[is0];
dict[is1] = ++dict[is1];
}
console.log(dict);
return Math.max(...Object.values(dict));
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = {};
for (let rowId = startRowId; rowId > -1; --rowId) {
let is0 = '';
let is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = (dict[is0] ? 1 : dict[is0]+1);
dict[is1] = ++dict[is1];
}
console.log(dict);
return Math.max(...Object.values(dict));
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = {};
for (let rowId = startRowId; rowId > -1; --rowId) {
let is0 = '';
let is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = dict[is0] ? 1 : ++dict[is0];
dict[is1] = dict[is0] ? 1 : ++dict[is0];
dict[is1] = ++dict[is1];
}
console.log(dict);
return Math.max(...Object.values(dict));
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = {};
for (let rowId = startRowId; rowId > -1; --rowId) {
let is0 = '';
let is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = dict[is0] ? 1 : ++dict[is0];
dict[is1] = dict[is1] ? 1 : ++dict[is1];
}
console.log(dict);
return Math.max(...Object.values(dict));
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = {};
for (let rowId = startRowId; rowId > -1; --rowId) {
let is0 = '';
let is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = dict[is0] ? 1 : ++dict[is0];
dict[is1] = dict[is1] ? 1 : ++dict[is1];
}
console.log(dict);
return Math.max(...Object.values(dict));
}
[[0, 0, 0, 0], [0, 1, 0, 0], [1, 0, 1, 1]]
[[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0]]
Invalid result type, integer expected, non-integer number foundstdout:
{ '1': NaN, '320': NaN, '3210': NaN, '': NaN }
Invalid result type, integer expected, non-integer number foundstdout:
{ '20': NaN, '31': NaN }
Invalid result type, integer expected, non-integer number foundstdout:
{ '1': NaN, '320': NaN, '3210': NaN, '': NaN }
Invalid result type, integer expected, non-integer number foundstdout:
{ '20': NaN, '31': NaN }
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = {};
for (let rowId = startRowId; rowId > -1; --rowId) {
let is0 = '';
let is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = dict[is0] ? ++dict[is0];
dict[is1] = dict[is1] ? ++dict[is1] : ;
}
console.log(dict);
return Math.max(...Object.values(dict));
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = {};
for (let rowId = startRowId; rowId > -1; --rowId) {
let is0 = '';
let is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = dict[is0] ? ++dict[is0] : 1;
dict[is1] = dict[is1] ? ++dict[is1] : 1;
}
console.log(dict);
return Math.max(...Object.values(dict));
}
[[0, 0, 0, 0], [0, 1, 0, 0], [1, 0, 1, 1]]
[[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0]]
{ '1': 2, '320': 2, '3210': 1, '': 1 }
{ '20': 4, '31': 4 }
function result: 2
{ '1': 2, '320': 2, '3210': 1, '': 1 }
function result: 4
{ '20': 4, '31': 4 }
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = {};
for (let rowId = startRowId; rowId > -1; --rowId) {
let is0 = '';
let is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = dict[is0] ? ++dict[is0] : 1;
dict[is1] = dict[is1] ? ++dict[is1] : 1;
}
return Math.max(...Object.values(dict));
}
[[0, 0, 0, 0], [0, 1, 0, 0], [1, 0, 1, 1]]
[[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0]]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = {};
for (let rowId = startRowId; rowId > -1; --rowId) {
let is0 = '';
let is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = dict[is0] ? ++dict[is0] : 1;
dict[is1] = dict[is1] ? ++dict[is1] : 1;
}
return Math.max(...Object.values(dict));
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = {};
for (let rowId = startRowId; rowId > -1; --rowId) {
let is0 = '';
let is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = dict[is0] ? ++dict[is0] : 1;
dict[is1] = dict[is1] ? ++dict[is1] : 1;
}
return Math.max(...Object.values(dict));
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = {};
for (let rowId = startRowId; rowId > -1; --rowId) {
let is0 = '';
let is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = dict[is0] ? ++dict[is0] : 1;
dict[is1] = dict[is1] ? ++dict[is1] : 1;
}
return Math.max(...Object.values(dict));
}
[[0, 0, 0, 0], [0, 1, 0, 0], [1, 0, 1, 1]]
[[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0]]
[[0, 1, 1, 1], [1, 0, 0, 0], [0, 0, 0, 1], [1, 0, 1, 0], [1, 0, 1, 0]]
function result: 2
function result: 4
function result: 2
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = {};
for (let rowId = startRowId; rowId > -1; --rowId) {
let is0 = '';
let is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = dict[is0] ? ++dict[is0] : 1;
dict[is1] = dict[is1] ? ++dict[is1] : 1;
}
return Math.max(...Object.values(dict));
}
[[0, 0, 0, 0], [0, 1, 0, 0], [1, 0, 1, 1]]
[[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0]]
[[0, 1, 1, 1], [1, 0, 0, 0], [0, 0, 0, 1], [1, 0, 1, 0], [1, 0, 1, 0]]
function result: 2
function result: 4
function result: 2
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = {};
for (let rowId = startRowId; rowId > -1; --rowId) {
let is0 = '';
let is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = dict[is0] ? ++dict[is0] : 1;
dict[is1] = dict[is1] ? ++dict[is1] : 1;
}
return Math.max(...Object.values(dict));
}
[[0, 0, 0, 0], [0, 1, 0, 0], [1, 0, 1, 1]]
[[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0]]
[[0, 1, 1, 1], [1, 0, 0, 0], [0, 0, 0, 1], [1, 0, 1, 0], [1, 0, 1, 0]]
function result: 2
function result: 4
function result: 2
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const rows = A.length;
if (!rows) {
return 0;
}
const columns = A[0].length;
const startRowId = rows-1;
const startColId = columns-1;
const dict = {};
for (let rowId = startRowId; rowId > -1; --rowId) {
let is0 = '';
let is1 = '';
for (let colId = startColId; colId > -1; --colId) {
if (A[rowId][colId] === 0) is0 += colId;
else is1 += colId;
}
dict[is0] = dict[is0] ? ++dict[is0] : 1;
dict[is1] = dict[is1] ? ++dict[is1] : 1;
}
return Math.max(...Object.values(dict));
}
The solution obtained perfect score.