Triangle and Points
Updated
Problem statement
You are given the coordinates of a triangle with three vertices:
(x1, y1)(x2, y2)(x3, y3)
You are also given two points:
- Point
p = (xp, yp) - Point
q = (xq, yq)
Return the following code:
- Return
1if the three vertices cannot form a triangle. - Return
2if bothpandqlie inside the triangle. - Return
3if onlyplies inside the triangle. - Return
4if onlyqlies inside the triangle. - Return
5if neither point lies inside the triangle.
Boundary rule: A point on an edge or exactly on a vertex is considered inside the triangle.
Input: The triangle coordinates x1, y1, x2, y2, x3, y3, followed by the point coordinates xp, yp, xq, yq.
Function
triangleAndPoints(x1: int, y1: int, x2: int, y2: int, x3: int, y3: int, xp: int, yp: int, xq: int, yq: int) → intExamples
Example 1
x1 = 0y1 = 0x2 = 5y2 = 0x3 = 0y3 = 5xp = 1yp = 1xq = 6yq = 6return = 3Only point p lies inside the triangle.
More GreyOrange interview questions
Similar questions at other companies
- Overlapping Random Time WindowsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Squared Frobenius Norm of a Reflect-and-Stretch MapWalleye Capital · OA
- Circles RelationshipIBM · OAIBM interview questions
- Slope of a Nonvertical LineMorgan Stanley · OAMorgan Stanley interview questions
- Cyber Beacon DetectionRippling · OARippling interview questions
- Do They Belong?Goldman Sachs · OAGoldman Sachs interview questions
- Closest Point to a LineAdobe · OAAdobe interview questions
- Range of a Third CorrelationTower Research Capital · PHONE SCREEN
- Three Points in a Semicircle: Monte Carlo EstimateSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Union Area of Two RectanglesDocuSign · PHONE SCREENDocuSign interview questions