I have been struggling with the 2D version of finding Longest Arithmetic Subsequence .
Given a set of 2D points in integers, is there an efficient algorithm that finds the largest subset of these points that form a NxM rectangular grid (e.g. 7x3, 4x4, 1x3, 2x1, 1x1) pattern, where the grid size is calculated as NxM? Note that the grid pattern can have different step sizes along X and Y directions. Also, single row (1xM), single column (Nx1) and single element (1x1) are also considered special rectangular grid patterns.
For points in the figure, the algorithm should return the 3x3 rectangular grid pattern of size 9 in red

All suggestions and references are greatly appreciated!