Largest Triangle Area - Problem
Find the Maximum Triangle Area from Points

You're given an array of points on a 2D coordinate plane, where each point is represented as [x, y]. Your task is to find the largest possible area of a triangle that can be formed by selecting any three different points from the array.

Goal: Return the area of the largest triangle
Input: Array of points points[i] = [xi, yi]
Output: Maximum triangle area as a floating-point number

The area calculation uses the mathematical formula for triangle area given three vertices. Answers within 10^-5 of the actual answer will be accepted, so you don't need to worry about extreme precision.

Input & Output

example_1.py โ€” Basic Triangle
$ Input: points = [[0,0],[0,1],[1,0],[0,2],[2,0]]
โ€บ Output: 2.0
๐Ÿ’ก Note: The largest triangle is formed by points [0,0], [0,2], and [2,0] with area = 0.5 * |0*(2-0) + 0*(0-0) + 2*(0-2)| = 0.5 * 4 = 2.0
example_2.py โ€” Collinear Points
$ Input: points = [[1,0],[0,0],[2,0]]
โ€บ Output: 0.0
๐Ÿ’ก Note: All three points are collinear (on the same line), so they cannot form a triangle. The area is 0.
example_3.py โ€” Square Formation
$ Input: points = [[0,0],[1,0],[0,1],[1,1]]
โ€บ Output: 0.5
๐Ÿ’ก Note: Multiple triangles can be formed, but the maximum area is 0.5 from triangles like [0,0], [1,0], [0,1]

Visualization

Tap to expand
Area: 7,500Area: 11,500 (MAX)Compare all possible triangles to find maximum area
Understanding the Visualization
1
Examine All Combinations
Check every possible set of three points
2
Calculate Areas
Use the coordinate formula to find each triangle's area
3
Track Maximum
Keep the largest area found so far
Key Takeaway
๐ŸŽฏ Key Insight: For geometric problems like finding maximum triangle area, brute force checking all combinations is often the optimal approach since geometric constraints don't allow for typical optimization shortcuts.

Time & Space Complexity

Time Complexity
โฑ๏ธ
O(nยณ)

Three nested loops to check all combinations of three points

n
2n
โš  Quadratic Growth
Space Complexity
O(1)

Only using a few variables to store coordinates and maximum area

n
2n
โœ“ Linear Space

Constraints

  • 3 โ‰ค points.length โ‰ค 50
  • -50 โ‰ค xi, yi โ‰ค 50
  • All points are unique
  • Answers within 10-5 of the actual answer will be accepted
Asked in
Amazon 15 Google 12 Microsoft 8 Meta 6
28.5K Views
Medium Frequency
~12 min Avg. Time
850 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