Convex Hull & Computational Geometry for Interviews
Computational geometry questions test your ability to reason about spatial relationships. The convex hull—the smallest convex polygon containing all points—is a classic problem.
Problem Definition
Given n points on a 2D plane, find the smallest convex polygon that contains all points.
Graham Scan
O(n log n) algorithm using angular sorting and a stack:
def convex_hull_graham(points):
if len(points) < 3:
return points
# Find bottommost point (or leftmost if tie)
start = min(points, key=lambda p: (p[1], p[0]))
points.remove(start)
# Sort by polar angle with start point
def polar_angle(p):
return math.atan2(p[1] - start[1], p[0] - start[0])
points.sort(key=polar_angle)
points.insert(0, start)
# Cross product: positive if counterclockwise turn
def cross(o, a, b):
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])
stack = []
for p in points:
while len(stack) >= 2 and cross(stack[-2], stack[-1], p) <= 0:
stack.pop()
stack.append(p)
return stack
Jarvis March (Gift Wrapping)
O(nh) where h is the number of hull points. Better when the hull has few points:
def convex_hull_jarvis(points):
n = len(points)
if n < 3:
return points
def cross(o, a, b):
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])
# Find leftmost point
hull = []
leftmost = min(range(n), key=lambda i: points[i][0])
p = leftmost
while True:
hull.append(p)
q = (p + 1) % n
for i in range(n):
if cross(points[p], points[i], points[q]) > 0:
q = i
p = q
if p == leftmost:
break
return [points[i] for i in hull]
Andrew's Monotone Chain
Often cleaner to implement—sort by x-coordinate and build upper/lower hulls:
def convex_hull_monotone(points):
points = sorted(set(points))
if len(points) <= 1:
return points
def cross(o, a, b):
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])
lower = []
for p in points:
while len(lower) >= 2 and cross(lower[-2], lower[-1], p) <= 0:
lower.pop()
lower.append(p)
upper = []
for p in reversed(points):
while len(upper) >= 2 and cross(upper[-2], upper[-1], p) <= 0:
upper.pop()
upper.append(p)
return lower[:-1] + upper[:-1]
Interview Applications
Point in Polygon
Use ray casting—count intersections of a horizontal ray with polygon edges.
Line Segment Intersection
Check if two segments intersect using orientation tests.
Closest Pair of Points
Divide and conquer—O(n log n) solution.
Interview Tips
- Handle edge cases. Three collinear points, duplicate points, all points on a line.
- Know your cross product. Positive = counterclockwise, negative = clockwise, zero = collinear.
- Numerical precision. Using integers or fractions avoids floating-point issues.
- Common follow-ups: "Find the diameter of the point set" (rotating calipers), "Is this point inside the convex hull?" (binary search on hull edges).
Ready to practice for your next interview? Interview Simulator gives you AI-powered feedback on your responses — behavioral, technical, and system design. Start with 3 free practice interviews today.
Try Interview Simulator free →
Master the most common coding interview patterns to ace your technical rounds.
For technical interview preparation, our system design guide is essential reading.
Don't neglect behavioral preparation — see our behavioral interview guide.
Your resume is the first impression — get it right with our resume guide.
{
"@context": "https://schema.org",
"@type": "BlogPosting",
"headline": "Convex Hull & Computational Geometry for Interviews",
"description": "Master convex hull algorithms—Graham scan, Jarvis march, and geometry interview patterns that appear in tech screens.",
"datePublished": "2026-03-21",
"author": {
"@type": "Organization",
"name": "CodeSwiftr Team"
},
"url": "https://codeswiftr.com/blog/convex-hull-computational-geometry"
}
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
{
"@type": "Question",
"name": "How should I structure my technical interview preparation?",
"acceptedAnswer": {
"@type": "Answer",
"text": "A structured 8–12 week preparation plan is most effective. Week 1–4: data structures and algorithms fundamentals using LeetCode easy-to-medium problems. Week 5–7: system design patterns using resources like the System Design Primer. Week 8–10: behavioral interview preparation with the STAR method. Week 11–12: company-specific mock interviews and review. Consistency matters more than intensity — 1–2 hours per day beats irregular all-day sessions."
}
},
{
"@type": "Question",
"name": "What is the STAR method and how should I use it in interviews?",
"acceptedAnswer": {
"@type": "Answer",
"text": "STAR stands for Situation, Task, Action, Result. It is the standard framework for answering behavioral interview questions. Situation: briefly describe the context (1–2 sentences). Task: explain your specific responsibility. Action: detail the steps you personally took — use 'I' not 'we'. Result: quantify the outcome wherever possible (e.g., 'reduced latency by 40%', 'increased conversion rate by 12%'). Keep each answer to 2–3 minutes."
}
},
{
"@type": "Question",
"name": "What LeetCode difficulty level should I focus on?",
"acceptedAnswer": {
"@type": "Answer",
"text": "For FAANG interviews, focus 20% on easy, 60% on medium, and 20% on hard problems. Easy problems build speed and confidence. Medium problems represent the most common interview difficulty at top companies. Hard problems appear mostly at Google, Meta, and specialised algorithmic roles. Do not skip easy problems — many candidates fail by overthinking genuinely simple questions that require clean, efficient solutions."
}
},
{
"@type": "Question",
"name": "How important is system design compared to coding in tech interviews?",
"acceptedAnswer": {
"@type": "Answer",
"text": "At mid-level and senior positions, system design carries equal or greater weight than coding. Entry-level and new-grad interviews are predominantly coding-focused. Senior and staff-level interviews dedicate one or two full rounds to system design. Master the core components: load balancers, databases (SQL vs NoSQL trade-offs), caches (Redis, Memcached), message queues (Kafka, SQS), CDNs, and API design. Practice designing real systems you use daily — the interviewer values practical reasoning over textbook answers."
}
}
]
}
Explore Related Topics
- Coding Interview: 6-Week Preparation Plan (2026)
- Interview Simulator vs LeetCode: Why AI Mock Interviews...
- Palantir Interview Guide 2026: Forward-Deployed...