Largest Triangle Area - 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.
Input & Output
Example 1 — Basic Triangle
$
Input:
points = [[0,0],[0,1],[1,0],[2,1],[2,2]]
›
Output:
1.5
💡 Note:
The largest triangle is formed by points [0,1], [1,0], [2,2] with area = |0(0-2) + 1(2-1) + 2(1-0)| / 2 = |0 + 1 + 2| / 2 = 1.5
Example 2 — Minimum Case
$
Input:
points = [[1,0],[0,0],[0,1]]
›
Output:
0.5
💡 Note:
Only one triangle possible with points forming a right triangle, area = 0.5 * 1 * 1 = 0.5
Example 3 — Collinear Points
$
Input:
points = [[0,0],[1,1],[2,2],[3,4]]
›
Output:
1.0
💡 Note:
Points [0,0], [1,1], [2,2] are collinear (area = 0), largest triangle uses [0,0], [2,2], [3,4] with area = |0(2-4) + 2(4-0) + 3(0-2)| / 2 = |0 + 8 - 6| / 2 = 1.0
Constraints
- 3 ≤ points.length ≤ 50
- -50 ≤ xi, yi ≤ 50
- All the given points are unique.
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code