Collinearity

Given a matrix points with exactly three rows and two columns, each row gives the integer coordinates [x, y] of one point. Return true when all three points…

Given a matrix `points` with exactly three rows and two columns, each row gives the integer coordinates `[x, y]` of one point. Return `true` when all three points lie on one straight line, including when two or more points are identical; otherwise return `false`. Compare the cross products of the two direction vectors from the first point: `(x2 - x1) * (y3 - y1)` and `(y2 - y1) * (x3 - x1)`. The points are collinear exactly when these products are equal.

- `points` has exactly 3 rows and exactly 2 columns per row. - `-1000000000 <= points[row][column] <= 1000000000`. - Every coordinate is one exact integer; booleans and non-integer values are invalid. - The visualizer always uses the required 3-by-2 shape.

Example 1: input points = [[0, 0], [1, 1], [2, 2]]; output true. Both direction vectors have the same slope, so the cross products are equal.

Example 2: input points = [[0, 0], [1, 2], [2, 1]]; output false. The two cross products differ, so the direction vectors do not lie on one line.

Example 3: input points = [[4, -2], [4, 7], [4, 100]]; output true. All three x-coordinates are equal, so the points lie on the same vertical line.

Category: Math & Numbers. Topic: math. Difficulty: Easy. Patterns: math.