All problems
1166EasyArrayMathGeometryPolygons

The Largest Triangle Between Pegs

Tracked in this browser only
Write code

Trains the technique from

LeetCode 812Largest Triangle Area

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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