Are All Points Collinear?
Updated
Problem statement
You are given a matrix points, where each row [x, y] is one point in the plane. Return true if all points lie on one straight line, and false otherwise.
Repeated coordinates are allowed. Zero, one, or two points are considered collinear. A vertical line is a valid straight line. Use exact integer geometry rather than floating-point slopes.
Function
arePointsCollinear(points: int[][]) → booleanExamples
Example 1
points = [[1,2],[2,4],[3,6]]return = trueAll points lie on y = 2x.
Example 2
points = [[0,0],[1,1],[1,2]]return = falseThe last point does not lie on the line through the first two.
Example 3
points = [[4,-1],[4,-1],[4,3]]return = trueThe duplicated point and the distinct point lie on the vertical line x = 4.
Constraints
0 <= points.length <= 10000.- Every row contains exactly two integer coordinates.
-1000000 <= x, y <= 1000000.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Merchant Payout Reserve CalculatorStripe · PHONE SCREENStripe interview questions
- Confusing Bib NumbersVerily · ONSITE INTERVIEW
- Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
- Plus OneDruva · ONSITE INTERVIEW
- Employee Count Median, Mean and ModeClay · PHONE SCREEN
- Matrix MultiplicationeBay · ONSITE INTERVIEWeBay interview questions
- Length of a Document Reached Through a Random TokenMercor · PHONE SCREENMercor interview questions
- Maximum Product of Three IntegersPelatro · ONSITE INTERVIEW
- Apply Affine Array TransformationsByteDance · PHONE SCREENByteDance interview questions
- Exponential Backoff DelaysWonderful · PHONE SCREEN