Check If It Is a Straight Line

Try to solve the Check If It Is a Straight Line problem.

Statement

You are given an array, coordinates, where each element in coordinates[i] =[x,y]= [x, y] represents the coordinates of a point on a 2D\text{2D} plane. Determine whether all the points in the array lie on a single straight line in the XY plane.

Constraints:

  • 22 \leq coordinates.length 1000\leq 1000

  • coordinates[i].length ==2== 2

  • 104-10^4 \leq coordinates[i][0]coordinates[i][1] 104\leq 10^4

  • coordinates do not contain any duplicate points.

Examples

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.