Erect the Fence
From LeetCode. Convex hull (Monotone Chain). Solve the geometry problem "Erect the Fence".
Examples
Input: [1,2,3]
Output: 0
Input: [2,3,4]
Output: 0
Hints
Core concept: Monotone Chain (Andrew's algorithm). Sort points by (x, y). Build lower hull left→right, then upper hull right→left. Combine.
For each point, while last 2 hull points + new point make clockwise turn (cross > 0 — using orientation (q-p)×(r-q)), pop last point. Push current point. Cross > 0 pops, cross ≤ 0 keeps (includes collinear on hull).
Collinear points on hull edges must be included per problem. Deduplicate where lower/upper hull meet at endpoints. Cross function: (q[1]-p[1])*(r[0]-q[0]) - (q[0]-p[0])*(r[1]-q[1]).
Erect the Fence
**From LeetCode.** Convex hull (Monotone Chain). Solve the geometry problem "Erect the Fence".