A harbor authority is placing marker beacons along the coastline so that a patrol boat can use them together as one sighting line for navigation. You are given the integer coordinates of every beacon that has been placed. Determine whether all of the beacons lie on one common straight line.
n, the number of beacons.n lines: two space-separated integers x and y, the coordinates of one beacon.Print YES if every beacon lies on a single straight line, otherwise print NO.
Example 1
Input
4 1 2 2 3 3 4 4 5
Expected
YES
Explanation
Beacons (1,2), (2,3), (3,4), (4,5) all lie on the line y = x + 1, so every point is aligned and the answer is YES.
Example 2
Input
4 1 1 2 2 3 3 4 7
Expected
NO
Explanation
The first three beacons (1,1), (2,2), (3,3) lie on the line y = x, but the fourth beacon (4,7) would need y = 4 to stay on that same line, so the beacons are not all aligned and the answer is NO.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →