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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
hash map
gcd normalization
geometry
duplicates
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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, ...


Submit Your Answer
Markdown supported