Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. For example, consider the following points.
The maximum number of points over the same straight line is 4. Those points are (1,1), (2,2), (3,3), and (4,4).
The first line consists of an integer,
n, that indicates the number of points
you will be given.
Each of the following
n lines consists of a pair of integers separated by one or more spaces
corresponding to the x and y components of a point.
Consider the following example.
The output consists of a single number, the maximum number of points that lie on the same straight line. For the example input, the maximum is 4.
Here is a Ruby implementation.
Want to read more?
I regularly write solutions to programming problems that you may or may not find in technical job interviews. I also love to explain those solutions and answer questions. If you would like to get the latest problem + solution, subscribe to the newsletter or subscribe via RSS. You can also follow me on Twitter, GitHub, and LinkedIn.