Largest Triangle Area
Real-world version: The Largest Triangle Between PegsThe 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.
def largest_triangle_area(pegs: list[list[int]]) -> float:public double largestTriangleArea(int[][] pegs)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Type of TriangleReal-world version: Naming the Shape of Three RodsEasy
- K Closest Points to OriginReal-world version: Nearest Survey StakesMedium
- Detonate the Maximum BombsReal-world version: Largest Chain of Quarry ChargesMedium
- Queries on Number of Points Inside a CircleReal-world version: Sensors Within Each Scan RadiusMedium