Problem Statement
You are given several points on a plane. Return the number of triples of distinct points such that all three points of the triple are on the same line. Two triples are considered different if there is a point that belongs to one of them and doesn't belong to the other.
You will be given int[]s x and y. The i-th point has coordinates (x[i], y[i]).
Definition
- Class:
- PointsOnALine
- Method:
- countTriples
- Parameters:
- int[], int[]
- Returns:
- int
- Method signature:
- int countTriples(int[] x, int[] y)
- (be sure your method is public)
Constraints
- x and y will each contain between 1 and 50 elements, inclusive.
- x and y will contain the same number of elements.
- Each element of x will be between -1000 and 1000, inclusive.
- Each element of y will be between -1000 and 1000, inclusive.
- The points given by x and y will be distinct.
Examples
{0,0,1,2,2}{0,2,1,0,2}Returns: 2
Points 0, 2 and 4 are on a line, and points 1, 2 and 3 are on a line.{0}{0}Returns: 0
There are no triples of points here.{0,0,0,0}{1,2,3,4}Returns: 4
Any three points are on the same line.