field of zeros and ones. A rectangle here is a set of four distinct cells holding 1 that are the corners of a rectangle whose sides run parallel to the edges of the grid. In other words, you pick two different rows and two different columns, and all four crossings must hold a 1.
What lies inside the rectangle or along its sides does not matter: only the corners are checked.
Return the number of such rectangles.field=[[1, 0, 1], [0, 1, 0], [1, 0, 1]] → 1
The only rectangle uses the four corners of the field: cells (0, 0), (0, 2), (2, 0) and (2, 2). The 1 in the middle belongs to no rectangle.
field=[[1, 1], [1, 1], [1, 1]] → 3
Any two of the three rows give a rectangle on both columns: 3 ways in total.
field=[[1, 1, 1, 1, 1]] → 0
A single row cannot supply four distinct corners.
field.length, field[i].length ≤ 200field[i][j] is 0 or 1field=[[1, 0, 1], [0, 1, 0], [1, 0, 1]]
1
Run checks the first 3 tests in your browser. Submit checks all 84 tests on the server, hidden ones included.