Skip to content

Practice Find Maximum Area of a Triangle

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3588
LeetCode Problem

Find Maximum Area of a Triangle

Problem Statement

You are given a 2D array coords of size n x 2, representing the coordinates of n points in an infinite Cartesian plane. Find twice the maximum area of a triangle with its corners at any three elements from coords, such that at least one side of this triangle is parallel to the x-axis or y-axis. Formally, if the maximum area of such a triangle is A, return 2 * A. If no such triangle exists, return -1. Note that a triangle cannot have zero area.

Source: Find Maximum Area of a Triangle on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
coords = [[1,1],[1,2],[3,2],[3,3]]
Output
2

# Example 2

Input
coords = [[1,1],[2,2],[3,3]]
Output
-1

Constraints

1 <= n == coords.length <= 10^5
1 <= coords[i][0], coords[i][1] <= 10^6
All coords[i] are unique.

Related LeetCode Problems

Practice more problems similar to Find Maximum Area of a Triangle.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.