Problem Statement
A farmer has several trees planted, the locations of which are given in int[]s x and y, where (x[i], y[i]) indicates the location of the i-th tree. The farmer notices that some of them form straight lines with one another and wonders, what is the largest numver of trees that are perfectly colinear with each other?
Definition
- Class:
- TreeLine
- Method:
- longest
- Parameters:
- int[], int[]
- Returns:
- int
- Method signature:
- int longest(int[] x, int[] y)
- (be sure your method is public)
Constraints
- x will have between 1 and 50 elements, inclusive.
- x and y will have the same number of elements.
- Each element of x will be between 0 and 1000, inclusive.
- Each element of y will be between 0 and 1000, inclusive.
- No elements of x and y will refer to the same point.
Examples
{0, 3, 6}{0, 3, 6}Returns: 3
All three trees for a line.{0, 3, 6}{0, 3, 7}Returns: 2
Notice the last tree is not in line with the first two.{0, 3, 6, 20, 12}{0, 3, 0, 20, 11}Returns: 3
Trees 0, 1 and 3 line up, the other two do not.