Count the number of right triangles that can be formed from points on a grid or in an array-based coordinate set.
Given a set of points in the plane, count how many distinct triangles formed by three points are right triangles.
A triangle is considered a right triangle if one of its angles is exactly .
Your task is to return the total number of such triangles that can be formed using the given points. Each valid triangle should be counted once, regardless of the order in which its vertices are chosen.
(x, y).Example 1
Input
points = [[0,0],[1,0],[0,1],[2,0],[0,2]]
Output
6
Explanation
Right triangles can be formed by choosing a point on the x-axis and a point on the y-axis with the origin as the right-angle vertex, plus the larger axis-aligned variants. The distinct right triangles are counted once each.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.