The Convex Polygon interview question asks you to determine if a given set of points, which form a polygon in order, constitutes a convex polygon. A polygon is convex if all its interior angles are less than 180 degrees. If any interior angle is greater than 180 degrees, the polygon is "concave."
Google asks the Convex Polygon coding problem to evaluate your knowledge of computational geometry. It tests whether you can apply mathematical concepts like the "cross product" to a programming problem. It’s a "Medium" difficulty task that reveals if you can think about 2D space and vector orientation systematically.
The primary Geometry interview pattern used here is the Cross Product of vectors.
A, B, and C, calculate the cross product of vectors BA and BC.Points: (0,0), (2,0), (2,2), (0,2) (A square)
(2,0): Vector (0,0)-(2,0) and (2,2)-(2,0). Cross product is positive.(2,2): Next vector pair. Cross product is positive.(0,2): Next vector pair. Cross product is positive.(0,0): Final vector pair. Cross product is positive.
Since all turns are in the same direction, it is a convex polygon.Brush up on the formula for the 2D cross product: (x2-x1)(y3-y2) - (y2-y1)(x3-x2). This is the most efficient way to check the "handedness" of a turn without calculating actual angles.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Queries on Number of Points Inside a Circle | Medium | Solve | |
| Find the Largest Area of Square Inside Two Rectangles | Medium | Solve | |
| Minimum Area Rectangle II | Medium | Solve | |
| Erect the Fence II | Hard | Solve | |
| Valid Boomerang | Easy | Solve |