Assign a Verified Address to Its Neighborhood Polygon

Last updated: November 29, 2026

Quick Overview

Given a member's address as a projected (x, y) point and a list of neighborhoods, each a simple polygon of vertices, return the id of the neighborhood that contains the point, or None. A point exactly on a boundary counts as inside.

Nextdoor
Coding & Algorithms
Software Engineer
Nextdoor
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a member's address as a projected (x, y) point and a list of neighborhoods, each a simple polygon of vertices, return the id of the neighborhood that contains the point, or None. A point exactly on a boundary counts as inside.

Every Nextdoor member is placed in exactly one neighborhood based on their verified address, so point-in-polygon is a natural warm-up for backend and geo-adjacent roles. The interviewer checks that you know the ray casting idea, handle boundary and vertex cases deliberately, and think about a cheap filter before the exact test.

What the Interviewer Expects
  • Explain ray casting (or winding number) and why parity of crossings decides inside
  • Handle points that lie exactly on an edge with an explicit rule
  • Avoid double counting when the ray passes through a vertex by using a half-open comparison
  • Add a bounding box pre-check before the exact O(V) test
  • State complexity per lookup and per batch
Key Topics to Cover
Point in polygon
Ray casting
Computational geometry
Bounding box filter
Spatial 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
  • How would you serve this for millions of lookups a day against tens of thousands of polygons?
  • What changes if polygons can have holes, such as a park excluded from a neighborhood?
  • Two neighborhoods overlap because of a drawing error. How do you choose one deterministically?
  • Why should you not run this directly on raw latitude and longitude near the poles or the antimeridian?
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: a point (x, y) in a planar projection and a list of (neighborhood_id, polygon) where each polygon is a list of vertices in order, not self-intersecting. Output the first neighborhood contai...

High-Level Design

For each candidate polygon, first reject it with a bounding box check (four comparisons). For survivors, cast a horizontal ray to the right of the point and count edge crossings. Odd count means insid...


Submit Your Answer
Markdown supported

Related Questions