> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Largest Triangle Area Python Solution

> Tested Python solution for LeetCode 812 with 19 pytest cases. Generate a practice environment with lcpy.

LeetCode 812, [Easy](/catalog/easy). Topics: [Array](/catalog/topics/array), [Math](/catalog/topics/math), [Geometry](/catalog/topics/geometry), Polygons. [View on LeetCode](https://leetcode.com/problems/largest-triangle-area/description/).

Generate this problem as a practice environment: tested reference solution, 19 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 812   # by problem number
lcpy gen -s largest_triangle_area   # by problem name
```

## Problem

Given an array of points on the X-Y plane `points` where `points[i] = [xi, yi]`, return *the area of the largest triangle that can be formed by any three different points*. Answers within `10^-5` of the actual answer will be accepted.

### Examples

![Example 1](https://s3-lc-upload.s3.amazonaws.com/uploads/2018/04/04/1027.png)

```
Input: points = [[0,0],[0,1],[1,0],[0,2],[2,0]]
Output: 2.00000
Explanation: The five points are shown in the above figure. The red triangle is the largest.
```

```
Input: points = [[1,0],[0,0],[0,1]]
Output: 0.50000
```

### Constraints

* 3 \<= points.length \<= 50
* -50 \<= xi, yi \<= 50
* All the given points are unique.

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/largest_triangle_area/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/largest_triangle_area/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from itertools import combinations


class Solution:
    # Time: O(n^3)
    # Space: O(1)
    def largest_triangle_area(self, points: list[list[int]]) -> float:
        best = 0.0
        for (ax, ay), (bx, by), (cx, cy) in combinations(points, 3):
            area = abs((bx - ax) * (cy - ay) - (by - ay) * (cx - ax)) / 2
            best = max(best, area)
        return best
```

## Complexity

| Time | Space |
| - | - |
| O(n^3) | O(1) |

## Tags


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.