corners, where corners[i] = [x, y], and the fence runs from post to post in order, then from the last post back to the first.
The fence is guaranteed never to cross or touch itself: exactly two neighbouring sections meet at each post, and sections share no other points.
Return True if the resulting polygon is convex, meaning none of its corners is pushed inward, and False otherwise. A post in the middle of a straight stretch of fence (three consecutive posts on one line) does not break convexity.corners=[[0, 0], [4, 0], [6, 3], [2, 5], [-1, 2]] → True
Walking along the outline we always turn the same way (left), so there are no dents.
corners=[[0, 0], [6, 0], [6, 6], [3, 2], [0, 6]] → False
At [3, 2] the outline turns the other way: that corner points inward.
corners=[[0, 0], [2, 0], [4, 0], [4, 3], [0, 3]] → True
The corner [2, 0] lies right on a straight side; that is not a dent, so the shape is convex.
corners=[[0, 0], [4, 0], [6, 3], [2, 5], [-1, 2]]
True
Run checks the first 3 tests in your browser. Submit checks all 69 tests on the server, hidden ones included.