Ctrl K

Posts in One Line

Easy
Fence posts have been dug in; posts[i] = [x, y] gives the position of the i-th post on the site plan. No two posts share a point. Return True if all the posts lie on a single straight line, and False otherwise.
Example 1
posts=[[0, 1], [2, 5], [-1, -1], [4, 9]] → True

Every post lies on the line y = 2x + 1.

Example 2
posts=[[3, 3], [3, -2], [4, 0]] → False

The first two posts stand on the vertical line x = 3, and the third is off it.

Constraints
  • 2 ≤ len(posts) ≤ 1000
  • len(posts[i]) == 2
  • -10⁴ ≤ x, y ≤ 10⁴
  • All points are distinct
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Biggest Triangle on the Board EasyShadows of Block Towers EasySurface of Cube Towers EasyHow a Rumor Spreads EasyThree Stakes Off the Line Easy
loading Python…
Input
posts=[[0, 1], [2, 5], [-1, -1], [4, 9]]
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 124 tests on the server, hidden ones included.