Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    3623 - Count Number of Trapezoids I.

    Medium

    You are given a 2D integer array points, where <code>pointsi = x<sub>i</sub>, y<sub>i</sub></code> represents the coordinates of the <code>i<sup>th</sup></code> 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 <code>10<sup>9</sup> + 7</code>.

    Example 1:

    Input: points = [1,0,2,0,3,0,2,2,3,2]

    Output: 3

    Explanation:

    There are three distinct ways to pick four points that form a horizontal trapezoid:

    • Using points [1,0], [2,0], [3,2], and [2,2].

    • Using points [2,0], [3,0], [3,2], and [2,2].

    • Using points [1,0], [3,0], [3,2], and [2,2].

    Example 2:

    Input: points = [0,0,1,0,0,1,2,1]

    Output: 1

    Explanation:

    There is only one horizontal trapezoid that can be formed.

    Constraints:

    • <code>4 <= points.length <= 10<sup>5</sup></code>

    • <code>–10<sup>8</sup><= x<sub>i</sub>, y<sub>i</sub><= 10<sup>8</sup></code>

    • All points are pairwise distinct.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer countTrapezoids(Array<IntArray> points)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait