Are All Points Collinear?
Problem statement
You are given a matrix points, where each row [x, y] is one point in the plane. Return true if all points lie on one straight line, and false otherwise.
Repeated coordinates are allowed. Zero, one, or two points are considered collinear. A vertical line is a valid straight line. Use exact integer geometry rather than floating-point slopes.
Function
arePointsCollinear(points: int[][]) → booleanExamples
Example 1
points = [[1,2],[2,4],[3,6]]return = trueAll points lie on y = 2x.
Example 2
points = [[0,0],[1,1],[1,2]]return = falseThe last point does not lie on the line through the first two.
Example 3
points = [[4,-1],[4,-1],[4,3]]return = trueThe duplicated point and the distinct point lie on the vertical line x = 4.
Constraints
0 <= points.length <= 10000.- Every row contains exactly two integer coordinates.
-1000000 <= x, y <= 1000000.