Count Number of Trapezoids I

You are given a 2D integer array points, where points[i] = [xi, yi] represents the coordinates of the i^th point on the Cartesian plane.

A horizontal trapezoid is a convex quadrilateral with at least one pair of horizontal sides (i.e. parallel to the x-axis). Two lines are parallel if and only if they have the same slope.

Return the number of unique horizontal trapezoids that can be formed by choosing any four distinct points from points.

Since the answer may be very large, return it modulo 10^9 + 7.

Example 1
Inputpoints = [[1,0],[2,0],[3,0],[2,2],[3,2]]
Output3
There are three distinct ways to pick four points that form a horizontal trapezoid.
Example 2
Inputpoints = [[0,0],[1,0],[0,1],[2,1]]
Output1
There is only one horizontal trapezoid that can be formed.

Constraints

  • 4 <= points.length <= 10^5
  • –10^8 <= xi, yi <= 10^8
  • All points are pairwise distinct.

Asked at 3 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate