Return Homes Inside a Buyer's Hand-Drawn Map Boundary

Last updated: November 29, 2026

Quick Overview

A buyer draws a free-form polygon on the map to limit their search. Given the polygon vertices and a list of homes with coordinates, return the ids of homes that fall inside it, including concave shapes.

Zillow
Coding & Algorithms
Software Engineer
Zillow
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


A buyer draws a free-form polygon on the map to limit their search. Given the polygon vertices and a list of homes with coordinates, return the ids of homes that fall inside it, including concave shapes.

Map search with a custom drawn boundary is a core Zillow search feature, and the geometry behind it is a natural onsite coding question for search and maps teams. The interviewer wants a correct point-in-polygon test that survives concave shapes and vertex hits, plus a sensible pre-filter before the exact test.

What the Interviewer Expects
  • Pick ray casting (or winding number) and explain why it handles concave polygons
  • Handle a ray passing exactly through a vertex using a half-open comparison
  • Pre-filter with the polygon's bounding box
  • Explain why planar math is fine at neighborhood scale
  • Discuss how a real index (geohash, R-tree, S2) changes the cost
Key Topics to Cover
computational geometry
ray casting
bounding box
geospatial indexing
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
  • Millions of listings: how do you avoid running the exact test on every home?
  • The user draws a polygon that crosses itself. What should the product do?
  • How would you return results sorted by distance to the polygon centroid?
  • Where would this logic live: client, search service, or the search engine's geo query?
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

Polygon is a list of (lat, lng) vertices in drawing order, implicitly closed, possibly concave, not self-intersecting. Homes are (id, lat, lng). Return ids inside. Drawn areas are a few miles acro...

High-Level Design

Two stages. First a cheap bounding-box reject using the polygon's min and max lat and lng. Then the exact test: cast a horizontal ray from the point toward increasing longitude and count edge crossing...


Submit Your Answer
Markdown supported

Related Questions