Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Point-In-Nonconvex Polygon
00:00
5 left

Point-In-Nonconvex Polygon

HardPython

Problem

How would you determine if a given 2D point lies inside a complex, non-convex polygon?

Implement point_in_polygon(point, polygon), where point is [x, y] and polygon is an ordered list of vertices forming a simple polygon. Return true only for points strictly inside; points outside, on an edge, or on a vertex return false. Example: point [2, 2] in square [[0, 0], [4, 0], [4, 4], [0, 4]] returns true; point [4, 2] returns false. Use integer coordinates with 3 <= len(polygon) <= 5000 and assume the polygon is non-self-intersecting.

Constraints

  • 3 <= len(polygon) <= 5000
  • Each vertex is an integer pair [x, y]
  • -10^9 <= x, y <= 10^9
  • The polygon is simple and vertices are listed in boundary order
  • The polygon has no zero-length edges
  • Points on edges or vertices are considered outside

Function Signature

def point_in_polygon(point, polygon):
Interviewer

Your question is Point-In-Nonconvex Polygon. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.