3623. Count Number of Trapezoids I Medium
1/**
2 * [3623] Count Number of Trapezoids I
3 *
4 * <p data-end="189" data-start="146">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.
5 * <p data-end="579" data-start="405">A horizontal trapezoid is a convex quadrilateral with <strong data-end="496" data-start="475">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.
6 * <p data-end="579" data-start="405">Return the <em data-end="330" data-start="297"> number of unique horizontal trapezoids that can be formed by choosing any four distinct points from points.
7 * Since the answer may be very large, return it modulo 10^9 + 7.
8 *
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io">points = [[1,0],[2,0],[3,0],[2,2],[3,2]]</span>
12 * Output: <span class="example-io">3</span>
13 * Explanation:
14 * <img alt="" src="https://assets.leetcode.com/uploads/2025/05/01/desmos-graph-6.png" style="width: 250px; height: 250px;" /> <img alt="" src="https://assets.leetcode.com/uploads/2025/05/01/desmos-graph-7.png" style="width: 250px; height: 250px;" /> <img alt="" src="https://assets.leetcode.com/uploads/2025/05/01/desmos-graph-8.png" style="width: 250px; height: 250px;" />
15 * There are three distinct ways to pick four points that form a horizontal trapezoid:
16 *
17 * <li data-end="247" data-start="193">Using points <code data-end="213" data-start="206">[1,0], <code data-end="222" data-start="215">[2,0], <code data-end="231" data-start="224">[3,2], and <code data-end="244" data-start="237">[2,2].
18 * <li data-end="305" data-start="251">Using points <code data-end="271" data-start="264">[2,0], <code data-end="280" data-start="273">[3,0], <code data-end="289" data-start="282">[3,2], and <code data-end="302" data-start="295">[2,2].
19 * <li data-end="361" data-start="309">Using points <code data-end="329" data-start="322">[1,0], <code data-end="338" data-start="331">[3,0], <code data-end="347" data-start="340">[3,2], and <code data-end="360" data-start="353">[2,2].
20 * </div>
21 * <strong class="example">Example 2:
22 * <div class="example-block">
23 * Input: <span class="example-io">points = [[0,0],[1,0],[0,1],[2,1]]</span>
24 * Output: <span class="example-io">1</span>
25 * Explanation:
26 * <img alt="" src="https://assets.leetcode.com/uploads/2025/04/29/desmos-graph-5.png" style="width: 250px; height: 250px;" />
27 * There is only one horizontal trapezoid that can be formed.
28 * </div>
29 *
30 * Constraints:
31 *
32 * 4 <= points.length <= 10^5
33 * –10^8 <= xi, yi <= 10^8
34 * All points are pairwise distinct.
35 *
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/count-number-of-trapezoids-i/
40// discuss: https://leetcode.com/problems/count-number-of-trapezoids-i/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45 pub fn count_trapezoids(points: Vec<Vec<i32>>) -> i32 {
46 0
47 }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_3623() {
58 }
59}
60Back
© 2026 bowen.ge All Rights Reserved.