Max Points on a Line
Updated
Problem statement
Given an array of two-dimensional integer points, return the maximum number of input points that lie on one straight line. Repeated coordinates are separate input points and each copy counts.
Use exact integer geometry. Do not compare floating-point slopes: nearby rational slopes may round to the same value, and vertical lines have no finite slope.
Function
maxPointsOnLine(points: int[][]) → intExamples
Example 1
points = [[1,1],[2,2],[3,3]]return = 3All three distinct points are on the same diagonal line.
Example 2
points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]return = 4Four points lie on the descending line through [1,4] and [4,1].
Example 3
points = [[0,0],[0,0],[1,1],[2,2],[1,0]]return = 4Both copies of [0,0] count on the line through [1,1] and [2,2].
Constraints
1 <= points.length <= 300.- Each row contains exactly two integer coordinates
[x, y]. -1000000 <= x, y <= 1000000.- Repeated coordinates are allowed; each occurrence counts separately.
More Microsoft Onsite Interview questions
- Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Max Points on a LineLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Max Points on a LineUber · PHONE SCREENUber interview questions
- Count Axis-Aligned and Rotated SquaresGoogle · PHONE SCREENGoogle interview questions
- Pro-Rata Order BookIMC Trading · ONSITE INTERVIEWIMC Trading interview questions
- Circle Intersection in Three DimensionsNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
- Volunteer Awards: Totals Divisible by KNutanix · ONSITE INTERVIEWNutanix interview questions
- Integers With Multiple Sum of Two CubesCharta Health · PHONE SCREEN · ONSITE INTERVIEWCharta Health interview questions
- Fractional Share Inventory FlatteningRobinhood · PHONE SCREEN · ONSITE INTERVIEWRobinhood interview questions
- Group-Relative Policy AdvantagesAmazon · ONSITE INTERVIEW
- Product Total With the Cheapest PromotionInstacart · ONSITE INTERVIEWInstacart interview questions
Microsoft interview experiences
- Microsoft OA Questions, October 2026: 4 Experiences
- Microsoft Experienced SWE Phone Screen: 1 Experience
- Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
- Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
- Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
- Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)