Convex Polygon

Try to solve the Convex Polygon problem.

Statement

You are given an array of points on the XY plane, where each point is represented as points[i] = [xi, yi][x_i, \space y_i]. These points, when connected sequentially, form a polygonA polygon is a two-dimensional (2D) geometric figure with straight lines connected to form a closed shape. Each line segment in the polygon is called an edge, and the points where two edges meet are called vertices..

Your task is to return TRUE if the polygon is convexA convex polygon is one with all interior angles of less than 180 degrees. Additionally, for any line drawn through the polygon, the line will intersect the polygon at most two points. and FALSE otherwise.

Note: It is guaranteed that the polygon formed by the given points is simple, meaning exactly two edges intersect at each vertex, and the edges do not intersect with each other elsewhere.

Constraints:

  • 33 \leq points.length 103\leq 10^3

  • points[i].length == 2

  • 104-10^4 \leq xix_i, yiy_i 104\leq 10^4

  • All the given points are unique.

Examples

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