FunctionRacerProblemsRace

Polygon Area

EasyMathPython, JavaScript, TypeScript, Java, C++

vertices lists the corners [x, y] of a simple polygon (its edges never cross) in order around the polygon, either clockwise or counterclockwise. Return twice the polygon's area as an integer. Hint: add up x1*y2 - x2*y1 over every edge, going back to the first vertex at the end.

Example 1

vertices [[0,0],[4,0],[4,3],[0,3]]
returns 24

A 4 by 3 rectangle has area 12, so 24.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Math problems