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: 2.0
💡 Note: The largest triangle is formed by points [0,0], [2,1], [2,2] with area = 2.0
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.5
💡 Note: Points [0,0], [1,1], [2,2] are collinear (area = 0), largest triangle uses [0,0], [2,2], [3,4]

Constraints

  • 3 ≤ points.length ≤ 50
  • -50 ≤ xi, yi ≤ 50
  • All the given points are unique.

Visualization

Tap to expand
Largest Triangle Area Problem[0,0][0,1][1,0][2,1][2,2]Try all C(5,3) = 10 combinationsLargest triangle: [0,0], [2,1], [2,2]Area = |0(1-2) + 2(2-0) + 2(0-1)| / 2 = 2.0Output: 2.0
Understanding the Visualization
1
Input Points
Array of coordinate points [[0,0],[0,1],[1,0],[2,1],[2,2]]
2
Generate All Triangles
Test all possible combinations of 3 points
3
Find Maximum Area
Return the largest area found: 2.0
Key Takeaway
🎯 Key Insight: Use the cross product formula |x₁(y₂-y₃) + x₂(y₃-y₁) + x₃(y₁-y₂)| / 2 to calculate triangle area efficiently
Asked in
Amazon 15 Google 12
28.5K Views
Medium Frequency
~15 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen