Check If It Is a Straight Line

You are given an integer array coordinates, where coordinates[i] = [x, y] represents the coordinate of a point. Check if these points make a straight line in the XY plane.

Return true if all the points lie on a single straight line, and false otherwise.

Example 1
Inputcoordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]
Outputtrue
All the points lie on the same straight line.
Example 2
Inputcoordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]
Outputfalse
The point [3, 4] does not lie on the same straight line as the others.

Constraints

  • 2 <= coordinates.length <= 1000
  • coordinates[i].length == 2
  • -10^4 <= coordinates[i][0], coordinates[i][1] <= 10^4
  • coordinates contains no duplicate point.

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate