Polygon Area (Doubled)

MediumMathGeometrySortingGraph

Description

Given the vertices of a simple polygon listed in order (clockwise or counter-clockwise) as integer (x, y) pairs, return twice its area as an integer. Use the shoelace formula.

Examples

Input:points = [[0,0],[4,0],[4,3]]
Output:12
Explanation:

Right triangle area 6, doubled 12.

Input:points = [[0,0],[2,0],[2,2],[0,2]]
Output:8
Explanation:

Unit square scaled, area 4, doubled 8.

Input:points = [[1,1],[5,1],[5,4],[1,4]]
Output:24
Explanation:

Rectangle 4x3 area 12, doubled 24.

Constraints

  • 3 ≤ vertices ≤ 100
  • -10⁶ ≤ coords ≤ 10⁶

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!