Skip to content
Discussion options

You must be logged in to vote

We need to count horizontal trapezoids formed by 4 points where at least one pair of sides is horizontal (parallel to x-axis). Here's my PHP solution:

Approach:

  1. Group points by y-coordinate - Since horizontal trapezoids require at least one pair of horizontal (parallel to x-axis) sides, points on the same horizontal line (same y-coordinate) can form these sides.
  2. Count combinations for each line - For each horizontal line with k points, there are C(k, 2) = k*(k-1)/2 ways to choose 2 points that could form a horizontal side.
  3. Count trapezoids across pairs of lines - A trapezoid requires two distinct horizontal lines. For two lines with counts a and b, the number of trapezoids using points f…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Dec 2, 2025
Maintainer Author

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Dec 2, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Dec 2, 2025
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants