#3588
Find Maximum Area of a Triangle
medium · 29.1% accepted · 52 likes · top 6%
array · hash table · math · greedy · geometry · enumeration
Description
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.
Solution