Citadel OA | Do They Belong? | Citadel Online Assessment Question
A triangle is formed by the three points a(x1, y1), b(x2, y2) and c(x3, y3) is a non-degenerate triangle if the following rules are respected (`|ab| is the length of the line between points a and b):
- |ab| + |bc| > |ac|
- |bc| + |ac| > |ab|
- |ab| + |ac| > |bc|
A point belongs to a triangle if it lies somewhere on or inside the triangle. Given two points p = (xp, yp) and q = (xq, yq), return the correct scenario number:
- 0. If the triangle abc does not form a valid non-degenerati triangle.
-
- If point p belongs to the triangle but point q does not.
-
- If point q belongs to the triangle but point p does not.
-
- If both points p and q belong to the triangle.
-
- If neither point p nor point q belong to the triangle.
Relevant Citadel OA Problems:
- Triplets
- Ways to Sum
- Consecutive Sum
- Disk Space Analysis
- Do They Belong?
- Global Maximum
- Initial Public Offering
- Inversions
- Portfolio Balances
- Prime Factor Visitation
- Profit Targets
- Sprint Training
- Throttling Gateway
- Birthday Card Collection
Input
x1
: see statementy1
: see statementx2
: see statementy2
: see statementx3
: see statementy3
: see statementxp
: see statementyp
: see statementxq
: see statementyq
: see statement
Output
an integer value represents the scenario
Examples
Example 1:
Input:
1x1 = 2 2y1 = 2 3x2 = 7 4y2 = 2 5x3 = 5 6y3 = 4 7xp = 4 8yp = 3 9xq = 7 10yq = 4
Output: 7
Explanation:
The point p(5, 4)
belongs to the triangle and the point q(7, 4)
does not.