632. Convex Polygon

You are given an array of points on the X-Y plane points where points[i] = [xi, yi]. The points form a polygon when joined sequentially.

Return true if this polygon is convex and false otherwise.

You may assume the polygon formed by given points is always a simple polygon. In other words, we ensure that exactly two edges intersect at each vertex and that edges otherwise don't intersect each other.

Example 1:

Input: points = [[0,0],[0,5],[5,5],[5,0]]

Output: true

Example 2:

Input: points = [[0,0],[0,10],[10,10],[10,0],[5,5]]

Output: false

Now Your Turn!

Pick the correct output for the given input

Input: points = [[0,0],[0,10],[10,17],[10,10],[5,10]]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 3 <= points.length <= 104
  • points[i].length == 2
  • -104 <= xi, yi <= 104
  • All the given points are unique.

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
bool isConvex(vector<vector<int>>& points) {
// Your code goes here
}
};
Test Case

Input:

Points