Most Check-Ins Lying on One Straight Line on the Map
Last updated: November 29, 2026
Quick Overview
Given integer coordinates of check-ins on a map (duplicates allowed), return the largest number of check-ins that lie on a single straight line.
Meta
November 29, 20260
0
0 solved
Given integer coordinates of check-ins on a map (duplicates allowed), return the largest number of check-ins that lie on a single straight line.
A hashing Hard with geometry, asked in Meta onsites to test careful key design. The interviewer focuses on representing slopes exactly (no floats), normalizing sign, and handling duplicate points.
What the Interviewer Expects
- Fixes an anchor point and groups other points by the slope to the anchor
- Represents slope as a reduced (dy, dx) pair using gcd, with normalized sign
- Handles vertical lines and duplicate points explicitly
- Avoids floating point slopes and explains why they fail
- Gives O(n^2) time and O(n) space per anchor
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return the line itself (two points on it) as well as the count.
- Points are streaming in; maintain the max line incrementally.
- Can you do better than O(n^2) if you only need lines with at least n/k points?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: pts, a list of (x, y) integer pairs, n up to about 300, coordinates up to 10^4 in absolute value. Output: the maximum number of points on any line. Duplicate coordinates count separately....
High-Level Design
Every line through two or more points passes through some anchor. For each anchor i, compare it only with later points j. Count exact duplicates of the anchor separately. For others, compute `dx, ...