Skip to main content

Salesforce

SalesForce OA 2023 - Non-Degenerate Triangle

Problem Description:

You are given three points: a(x1, y1), b(x2, y2), and c(x3, y3). The task is to check whether these points form a non-degenerate triangle. Additionally, you are provided two other points, p(x_p, y_p) and q(x_q, y_q). If the points form a valid triangle, you need to check whether p and q lie inside the triangle or not.

Input Format:

  • The first line contains two integers: x1 and y1, the coordinates of point a.
  • The second line contains two integers: x2 and y2, the coordinates of point b.
  • The third line contains two integers: x3 and y3, the coordinates of point c.
  • The fourth line contains two integers: xp and yp, the coordinates of point p.
  • The fifth line contains two integers: xq and yq, the coordinates of point q.

Output Format:

  • Print the following based on the conditions:
    • 0 if the points a, b, and c do not form a valid triangle (i.e., they are collinear).
    • 1 if p is inside the triangle and q is not.
    • 2 if q is inside the triangle and p is not.
    • 3 if both p and q are inside or on the triangle.
    • 4 if neither p nor q are inside or on the triangle.

Constraints:

  • ( 0 <= x1, y1, x2, y2, x3, y3, x_p, y_p, x_q, y_q <= 10^5 )

Example 1:

Input:

0 0
100 0
0 200
12 21
21 21

Output:

3

Example 2:

Input:

0 0
1 1
2 2
12 21
21 21

Output:

0