LC: 750. Number Of Corner Rectangles - spiralgo/algorithms GitHub Wiki
750. Number Of Corner Rectangles:
The Essence:
- If there are
Nobjects in an array, adding a new object would createNnew subarrays. - In
Ndifferent rows above some current row, if there are already two points at some indexesjandkin each of these columns, having also 2 points there in the current row would createNnew rectangles.
Details:
The number of rows that so far contain points at i as well as k can be kept using a matrix. The running count is added to the total when a new row also contains both points. The approach described here can also be implemented from a row-first perspective with traversal going from first column to the last.