Skip to content
DeepForgeby svx
All problems
MediumAlgorithmsal-322

Convex Hull Area

Problem

Return the area of the convex hull of a set of points as a float, or 0.0 when fewer than three non-collinear points are given.

Build the hull with the monotone chain algorithm keeping only strict left turns, then apply the shoelace formula and halve the absolute result. Duplicate points are ignored.

Hint

The shoelace sum is twice the signed area, so halve its absolute value.

Test cases

case 1
in: [[[0,0],[1,0],[1,1],[0,1]]]
expected: 1
case 2
in: [[[0,0],[2,0],[2,2],[0,2],[1,1]]]
expected: 4
case 3
in: [[[0,0],[3,0],[0,4]]]
expected: 6
case 4
in: [[[0,0],[1,0]]]
expected: 0
case 5
in: [[[5,5]]]
expected: 0
Starter codePython
def convex_hull_area(points):
    # Your code here
    pass

5 test cases · run your code against them in the editor