Show problems as
Classic problem #812EasyArrayMathGeometryPolygons

Largest Triangle Area

Real-world version: The Largest Triangle Between Pegs
Tracked in this browser only
Read Largest Triangle Area on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A board holds pegs at whole-number spots given by pegs, where pegs[i] = [x, y], and no two pegs share a spot.

Return the largest area of a triangle whose three corners are pegs. Three pegs standing in a straight line make a triangle of area zero.

Examples

Example 1

Input
pegs = [[0, 0], [3, 0], [0, 4]]
Output
6.0

The three pegs make a right-angled triangle with sides of 3 and 4 along the axes, so the area is half of twelve.

Example 2

Input
pegs = [[0, 0], [1, 1], [2, 2]]
Output
0.0

All three pegs stand on one line, so the only triangle available has no area.

Example 3

Input
pegs = [[-1, -1], [1, -1], [0, 1]]
Output
2.0

The base runs 2 across and the far peg stands 2 above it, so the area is half of four.

Constraints

  • 3 <= pegs.length <= 50
  • -50 <= pegs[i][0] <= 50
  • -50 <= pegs[i][1] <= 50
  • no two pegs share a spot

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def largest_triangle_area(pegs: list[list[int]]) -> float:
Java
public double largestTriangleArea(int[][] pegs)