|
| 1 | +<h2><a href="https://leetcode.com/problems/count-number-of-trapezoids-ii">3897. Count Number of Trapezoids II</a></h2><h3>Hard</h3><hr><p data-end="189" data-start="146">You are given a 2D integer array <code>points</code> where <code>points[i] = [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.</p> |
| 2 | + |
| 3 | +<p data-end="189" data-start="146">Return <em data-end="330" data-start="297">the number of unique </em><em>trapezoids</em> that can be formed by choosing any four distinct points from <code>points</code>.</p> |
| 4 | + |
| 5 | +<p data-end="579" data-start="405">A<b> </b><strong>trapezoid</strong> is a convex quadrilateral with <strong data-end="496" data-start="475">at least one pair</strong> of parallel sides. Two lines are parallel if and only if they have the same slope.</p> |
| 6 | + |
| 7 | +<p> </p> |
| 8 | +<p><strong class="example">Example 1:</strong></p> |
| 9 | + |
| 10 | +<div class="example-block"> |
| 11 | +<p><strong>Input:</strong> <span class="example-io">points = [[-3,2],[3,0],[2,3],[3,2],[2,-3]]</span></p> |
| 12 | + |
| 13 | +<p><strong>Output:</strong> <span class="example-io">2</span></p> |
| 14 | + |
| 15 | +<p><strong>Explanation:</strong></p> |
| 16 | + |
| 17 | +<p><img alt="" src="https://assets.leetcode.com/uploads/2025/04/29/desmos-graph-4.png" style="width: 250px; height: 250px;" /> <img alt="" src="https://assets.leetcode.com/uploads/2025/04/29/desmos-graph-3.png" style="width: 250px; height: 250px;" /></p> |
| 18 | + |
| 19 | +<p>There are two distinct ways to pick four points that form a trapezoid:</p> |
| 20 | + |
| 21 | +<ul> |
| 22 | + <li>The points <code>[-3,2], [2,3], [3,2], [2,-3]</code> form one trapezoid.</li> |
| 23 | + <li>The points <code>[2,3], [3,2], [3,0], [2,-3]</code> form another trapezoid.</li> |
| 24 | +</ul> |
| 25 | +</div> |
| 26 | + |
| 27 | +<p><strong class="example">Example 2:</strong></p> |
| 28 | + |
| 29 | +<div class="example-block"> |
| 30 | +<p><strong>Input:</strong> <span class="example-io">points = [[0,0],[1,0],[0,1],[2,1]]</span></p> |
| 31 | + |
| 32 | +<p><strong>Output:</strong> <span class="example-io">1</span></p> |
| 33 | + |
| 34 | +<p><strong>Explanation:</strong></p> |
| 35 | + |
| 36 | +<p><img alt="" src="https://assets.leetcode.com/uploads/2025/04/29/desmos-graph-5.png" style="width: 250px; height: 250px;" /></p> |
| 37 | + |
| 38 | +<p>There is only one trapezoid which can be formed.</p> |
| 39 | +</div> |
| 40 | + |
| 41 | +<p> </p> |
| 42 | +<p><strong>Constraints:</strong></p> |
| 43 | + |
| 44 | +<ul> |
| 45 | + <li><code>4 <= points.length <= 500</code></li> |
| 46 | + <li><code>–1000 <= x<sub>i</sub>, y<sub>i</sub> <= 1000</code></li> |
| 47 | + <li>All points are pairwise distinct.</li> |
| 48 | +</ul> |
0 commit comments