Most Map Pins That Lie on One Straight Road

Last updated: November 29, 2026

Quick Overview

Given n map pins with integer coordinates (duplicates allowed), return the maximum number of pins that lie on a single straight line.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given n map pins with integer coordinates (duplicates allowed), return the maximum number of pins that lie on a single straight line.

A Google onsite hashing and geometry question framed around detecting straight road segments in Google Maps pin data. The interviewer cares that you avoid floating point slopes by normalizing with gcd, handle vertical lines, and count duplicate points correctly.

What the Interviewer Expects
  • Fixes an anchor point and hashes the direction to every other point
  • Normalizes slopes as reduced integer pairs with a canonical sign
  • Handles vertical and horizontal lines
  • Counts duplicates of the anchor separately
  • States O(n^2) time
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
  • Why are floating point slopes dangerous here? Give a concrete failure.
  • Return the line itself, not just the count.
  • With millions of points, how would you find lines with at least 10% of points (randomized approach)?
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: list of (x, y) integer pairs, possibly with duplicates.
  • Output: the largest number of pins on any line.
  • n up to a few hundred or a few thousand....
High-Level Design

A line through anchor A is determined by its direction from A. For each anchor, compute (dx, dy) to every other point, divide by g = gcd(dx, dy), and make the sign canonical (dx positive, or dx = ...


Submit Your Answer
Markdown supported