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.
    1. If point p belongs to the triangle but point q does not.
    1. If point q belongs to the triangle but point p does not.
    1. If both points p and q belong to the triangle.
    1. If neither point p nor point q belong to the triangle.

Relevant Citadel OA Problems:

Input

  • x1: see statement
  • y1: see statement
  • x2: see statement
  • y2: see statement
  • x3: see statement
  • y3: see statement
  • xp: see statement
  • yp: see statement
  • xq: see statement
  • yq: 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.

Try it yourself

Solution

Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro